"""파트 선택 흐름: torchAdjust(part)/torchPart 가 올바른 파트에 기즈모 부착하는지."""
import asyncio, json
from playwright.async_api import async_playwright
URL='http://localhost:8090/DOZIKWORKS_OS_v5_locked.dc.html'
async def main():
    async with async_playwright() as p:
        br=await p.chromium.launch(channel='msedge',headless=True)
        pg=await br.new_page(viewport={'width':1000,'height':700})
        logs=[]; pg.on('console',lambda m: logs.append(m.text))
        await pg.goto(URL)
        await pg.wait_for_function("window.__dzw && window.__dzw._torchParts", timeout=15000)
        res=await pg.evaluate("""()=>{ const d=window.__dzw; const out={};
          d.torchAdjust(true, d._torchFlange);
          out.afterFlange = d._tc?.object?.name;
          out.sel1=d._torchSel?.name;
          d.torchPart('body');
          out.afterBody = d._tc?.object?.name;
          out.sel2=d._torchSel?.name;
          // 회전 모드 전환도 확인(선택 파트에 먹는지)
          d.selectTool('rotate'); out.mode=d._tc?.mode;
          d.torchAdjust(false); out.afterOff = d._tc?.object?.name || null;
          return out;
        }""")
        print(json.dumps(res,ensure_ascii=False,indent=1))
        print("--- 관련 로그 ---")
        for l in logs:
            if '토치' in l: print("  ",l)
        await br.close()
asyncio.run(main())
