"""虎牙旋转验证码 (rotate_auth / xz) 求解与捕获测试。""" from __future__ import annotations from pathlib import Path from core.huya.verification.capture import CaptchaCaptureRecord from core.huya.verification.solver import HuyaVerificationSolver def test_rotate_strategy_recognized(): """验证 rotate_auth.html 能被正确解析为 rotate_auth 类型。""" url = ( "https://aq.huya.com/p/safe_auth/rotate_auth.html?" "hideShareButton=1¶m=test_param&sceneType=4&appId=5008&mobile=001******5865" ) solver = HuyaVerificationSolver(page_url=url, account="test_rotate") solver._parse_strategy(url) assert solver.auth_type == "rotate_auth" def test_opencv_rotate_angle_accuracy(): """验证真实旋转验证码图片能够精准计算出旋转还原角度。""" sample_dir = Path("data/captcha_captures/20260906_132605_pt_auth_348f71b3") if not sample_dir.exists(): return bg_bytes = (sample_dir / "bg_restored.jpg").read_bytes() puzzle_bytes = (sample_dir / "puzzle.png").read_bytes() angle = HuyaVerificationSolver._opencv_rotate_angle(bg_bytes, puzzle_bytes) # 该样本的真值在 142 度左右 assert 138 <= angle <= 146 def test_capture_rotate_data(tmp_path: Path): """测试旋转验证码捕获能正确落盘并生成标注图与元数据。""" sample_dir = Path("data/captcha_captures/20260906_132605_pt_auth_348f71b3") if not sample_dir.exists(): return bg_bytes = (sample_dir / "bg_restored.jpg").read_bytes() puzzle_bytes = (sample_dir / "puzzle.png").read_bytes() record = CaptchaCaptureRecord( auth_type="rotate_auth", account="test_user", page_url="https://aq.huya.com/p/safe_auth/rotate_auth.html?param=123", scene_type="4", output_base_dir=tmp_path, ) out_dir = record.capture_rotate_data( code="test_code_1234", dtu_bytes=bg_bytes, puzzle_bytes=puzzle_bytes, restored_bg_bytes=bg_bytes, angle=142, raw_data={"code": "test_code_1234", "title": "旋转验证"}, ) assert (out_dir / "annotated.jpg").exists() assert (out_dir / "meta.json").exists() assert record.meta["solution"]["angle"] == 142 assert record.meta["auth_type"] == "rotate_auth"