"""前端 crop 归一化纯函数测试。 通过 node 执行 tests/test_crop_js.js(真实 JS 断言),验证框选矩形与 crop 比例的互转(含 letterbox 与越界钳制)。 """ import shutil import subprocess from pathlib import Path import pytest # 单体根目录:tests/ 的上一级。 WORKSPACE = Path(__file__).resolve().parent.parent JS_TEST = WORKSPACE / "tests" / "test_crop_js.js" def test_crop_js_normalization() -> None: """node 执行 crop 纯函数断言(TDD 红阶段先失败)。""" if shutil.which("node") is None: pytest.skip("环境无 node,跳过前端 crop 单测") result = subprocess.run( ["node", str(JS_TEST)], capture_output=True, text=True, cwd=str(WORKSPACE), ) assert result.returncode == 0, result.stderr