"""W-E: S14sh6 — production 과 동일하게 name_by_id 주입해 facing 복원 확인."""
import json
from pathlib import Path
from app.modules.pipeline.indoor_shared_pose_plan import build_pose_brief

CP = Path("/Users/manta/Documents/Projects/TheRoad-I1/projects/b0ad5c18-5140-4022-a2b0-805de0e5a385/checkpoints/episodes/0d30302a-51c8-4ac9-98e2-6cd9180512bf")
shots = json.loads((CP / "shot_staging" / "manifest.json").read_text())["data"]["shots"]

# entity name 맵 (production _load_name_by_short_id 와 동일 정보원 근사: entity_merge cp)
name_by_id = {}
for cpname in ("entity_merge", "entity_detail"):
    p = CP / cpname / "manifest.json"
    if not p.exists():
        continue
    d = json.loads(p.read_text()).get("data") or {}
    def walk(o):
        if isinstance(o, dict):
            sid, nm = o.get("short_id"), o.get("name")
            if isinstance(sid, str) and isinstance(nm, str) and sid and nm:
                name_by_id.setdefault(sid, nm)
            for v in o.values():
                walk(v)
        elif isinstance(o, list):
            for v in o:
                walk(v)
    walk(d)
    if name_by_id:
        break
print("name_by_id size:", len(name_by_id))

for sh in shots:
    if sh.get("scene_index") != 14 or sh.get("shot_index") not in (6, 8):
        continue
    b = build_pose_brief(sh, name_by_id=name_by_id)
    print(f"S14sh{sh['shot_index']}:")
    for f in b["figures"]:
        print(f"   pose={f['pose']!r} facing={f['facing']!r}")
        print(f"   gesture={f['gesture']!r}")
