"""Foreground isolated evidence run. No user data or external generation services.""" import json import os from pathlib import Path import sqlite3 import subprocess import tempfile import imageio_ffmpeg from PIL import Image, ImageDraw ROOT = Path(__file__).resolve().parents[1] OUT = ROOT.parent / "hel769-evidence" OUT.mkdir(exist_ok=True) # This database exists only for the duration of this foreground verification. with tempfile.TemporaryDirectory(prefix="hel769-isolated-", dir=OUT) as data: db = sqlite3.connect(Path(data) / "fixture.sqlite") db.execute("create table fixture_jobs (id integer primary key, purpose text, body text)") names = [ "镜头 07 · 首尾帧", "分镜草图 8/12", "Qwen 局部重绘 #62", "参考生视频 #21", "Krea2 文生图 #55", "镜头 06 · 首尾帧", ] workflow_names = [ "H3 首尾帧生视频", "Krea2 · 4 宫格故事板", "Qwen 2.1 · 局部重绘", "H3 参考生视频", "Krea2 · 文生图", "H3 首尾帧生视频", ] workflow_rows = [] for i in range(6): kind = "video" if i in (0, 3, 5) else "image" job = { "id": i + 1, "project_id": 1 if i in (0, 1, 5) else 0, "scene_id": 1 if i in (0, 1, 5) else None, "clip_id": None, "kind": kind, "workflow_id": i + 1, "status": ["running", "running", "pending", "failed", "done", "done"][i], "payload": { "title": names[i], "source": "workbench" if i in (0, 1, 5) else "studio-" + kind, "endpoint": {"id": "hel769-fake", "name": "5090D"}, }, "output_paths": ( ["HEL769-fixture-4.png" if i == 4 else "HEL769-fixture-video.mp4"] if i > 3 else [] ), "error": "OOM" if i == 3 else None, "created_at": f"2026-10-21T13:0{i}:00Z", "started_at": None, "completed_at": None, "retry_count": 0, "phase": "comfy_running" if i < 2 else None, } db.execute( "insert into fixture_jobs values (?,?,?)", (i + 1, "HEL-751 isolated sample correspondence; never production", json.dumps(job, ensure_ascii=False)), ) workflow_rows.append({ "id": i + 1, "name": workflow_names[i], "kind": kind, "media_io": {"in": [], "out": [kind]}, "tags": [], "favorite": False, "category": None, "model_family": None, "usage": "text2video" if kind == "video" else "text2image", "is_enabled": True, "needs_mapping": False, "input_schema": [{ "nodeId": "1", "label": "HEL769 fixture prompt", "role": "prompt", "kind": "textarea", "defaultValue": "", "required": True, }], "output_schema": [{"nodeId": "2", "label": "Output", "kind": kind}], "endpoint_id": "hel769-fake", }) db.commit() jobs = [json.loads(row[0]) for row in db.execute("select body from fixture_jobs order by id")] db.close() (Path(data) / "fixtures.json").write_text( json.dumps({"jobs": jobs, "workflows": workflow_rows}, ensure_ascii=False), encoding="utf-8", ) subprocess.run( [ imageio_ffmpeg.get_ffmpeg_exe(), "-y", "-f", "lavfi", "-i", "color=c=navy:s=320x180:r=24", "-f", "lavfi", "-i", "sine=frequency=440:sample_rate=44100", "-t", "2", "-c:v", "libx264", "-pix_fmt", "yuv420p", "-c:a", "aac", str(Path(data) / "video.mp4"), ], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True, ) env = os.environ | {"HEL769_OUT": str(OUT), "HEL769_DATA": data} subprocess.run(["node", "scripts/verify-hel769.mjs"], cwd=ROOT, env=env, check=True) print("Isolated database and media removed; all run-owned servers closed.") # Compose unchanged captures into review artifacts; never alter the original HTML. if not os.environ.get("HEL769_SKIP_VISUAL"): evidence = json.loads((OUT / "results.json").read_text()) lines = [ "| Theme / viewport | Element | Sample x,y,w,h | Actual x,y,w,h | Delta x,y,w,h |", "|---|---|---|---|---|", ] for measurement in evidence["measurements"]: name = f"{measurement['route']}-{measurement['theme']}-{measurement['width']}" sample = Image.open(OUT / f"{name}-sample.png").convert("RGB") actual = Image.open(OUT / f"{name}-actual.png").convert("RGB") pair = Image.new("RGB", (sample.width * 2, sample.height + 28), "#151515") ImageDraw.Draw(pair).text((12, 8), "Confirmed sample (left) / Isolated implementation (right)", fill="white") pair.paste(sample, (0, 28)) pair.paste(actual, (sample.width, 28)) pair.save(OUT / f"{name}-pair.png") for key, expected in measurement["sample"].items(): observed = measurement["actual"][key] if not expected or not observed: continue coordinates = ("x", "y", "width", "height") values = lambda row: ", ".join(f"{row[c]:.3f}" for c in coordinates) delta = {c: observed[c] - expected[c] for c in coordinates} lines.append( f"| {measurement['route']} {measurement['theme']} {measurement['width']}×{measurement['height']} " f"| {key} | {values(expected)} | {values(observed)} | {values(delta)} |" ) if key in ("themeName", "themeTone"): lines.append(f"| typography | {key} | {expected['font']} / {expected['line']} | {observed['font']} / {observed['line']} | font-size / line-height |") (OUT / "dimensions.md").write_text("\n".join(lines) + "\n", encoding="utf-8") import hashlib for f in sorted(OUT.glob("*-internal-sample.png")): actual = Image.open(str(f).replace("-sample.png", "-actual.png")).convert("RGB") sample = Image.open(f).convert("RGB") pair = Image.new("RGB", (sample.width, sample.height * 2 + 48), "#151515") draw = ImageDraw.Draw(pair) draw.text((8, 5), "Confirmed sample", fill="white") pair.paste(sample, (0, 24)) draw.text((8, sample.height + 29), "Isolated implementation", fill="white") pair.paste(actual, (0, sample.height + 48)) pair.resize((pair.width * 3, pair.height * 3), Image.Resampling.NEAREST).save(str(f).replace("-sample.png", "-pair-3x.png")) files = sorted(OUT.glob("*.png")) manifest = [{"file": f.name, "bytes": f.stat().st_size, "sha256": hashlib.sha256(f.read_bytes()).hexdigest()} for f in files] (OUT / "manifest.json").write_text(json.dumps(manifest, indent=2), encoding="utf-8")