from __future__ import annotations import os import sys import zipfile from pathlib import Path import pytest TOOLS = Path(__file__).resolve().parents[3] / "tools" sys.path.insert(0, str(TOOLS)) from package_hth_user_kits import VERSION, build_python_kit # noqa: E402 from zip_unix_modes import extract_zip_with_unix_modes # noqa: E402 def _wheel() -> Path | None: env = os.environ.get("HTH_SDK_WHEEL") if env and Path(env).is_file(): return Path(env) dist = Path(__file__).resolve().parents[1] / "dist" wheels = sorted(dist.glob("hth_sdk-*.whl")) if dist.is_dir() else [] return wheels[-1] if wheels else None def test_python_kit_zip_has_no_platform_guts(tmp_path): wheel = _wheel() if wheel is None: pytest.skip("build host/sdk/python wheel first") zpath = build_python_kit(wheel, tmp_path) assert zpath.is_file() with zipfile.ZipFile(zpath) as zf: names = zf.namelist() joined = "\n".join(names) assert "go.mod" not in joined assert ".proto" not in joined assert "reviews/" not in joined assert any(name.endswith("INSTALL.sh") for name in names) assert any(name.endswith("quickstart.py") for name in names) assert any(name.endswith("sample.jsonl") for name in names) assert f"hth-algorithm-python-kit-{VERSION}/" in names[0] or any( n.startswith(f"hth-algorithm-python-kit-{VERSION}/") for n in names ) stage = tmp_path / "stage" extract_zip_with_unix_modes(zpath, stage) install = next(stage.rglob("INSTALL.sh")) assert install.stat().st_mode & 0o111 def test_userkit_scripts_exist(): root = Path(__file__).resolve().parents[2] / "userkit" for name in ( "INSTALL.sh", "INSTALL.cmd", "START_HERE.sh", "SELF_TEST.sh", "install_kit.py", "README_FIRST_zh-CN.txt", ): assert (root / name).is_file(), name