Files
deepseek-harness/python/sdk/tests/test_release_version.py
T

73 lines
2.6 KiB
Python

"""Tests for repository-owned Python release versions."""
from __future__ import annotations
import json
import runpy
from pathlib import Path
from types import SimpleNamespace
import pytest
ROOT = Path(__file__).resolve().parents[3]
SCRIPT = ROOT / "scripts" / "build-python-release.py"
build_python_release = SimpleNamespace(**runpy.run_path(str(SCRIPT)))
def test_repository_version_matches_root_package_json() -> None:
expected = json.loads((ROOT / "package.json").read_text())["version"]
assert build_python_release.repository_version() == expected
def test_release_tag_is_optional_for_non_release_builds() -> None:
build_python_release.validate_release_tag(None, "1.2.3")
def test_release_tag_must_match_repository_version() -> None:
build_python_release.validate_release_tag("python-v1.2.3", "1.2.3")
with pytest.raises(ValueError, match="expected 'python-v1.2.3'"):
build_python_release.validate_release_tag("python-v1.2.4", "1.2.3")
def test_repository_version_rejects_non_stable_versions(tmp_path: Path) -> None:
(tmp_path / "package.json").write_text('{"version":"1.2.3-dev"}\n')
with pytest.raises(ValueError, match="must be stable X.Y.Z"):
build_python_release.repository_version(tmp_path)
def test_stage_sdk_keeps_distribution_module_and_runtime_pin_distinct(tmp_path: Path) -> None:
destination = tmp_path / "staging"
build_python_release.stage_sdk(destination, "1.2.3")
pyproject = (destination / "pyproject.toml").read_text()
assert 'name = "deepseek-harness-sdk"' in pyproject
assert 'version = "1.2.3"' in pyproject
assert '"deepseek-harness-runtime-bin==1.2.3"' in pyproject
assert (destination / "src" / "deepseek_harness" / "__init__.py").is_file()
@pytest.mark.parametrize(("target", "with_helper"), [("linux-x64", False), ("macos-arm64", True)])
def test_stage_runtime_copies_platform_payload(
tmp_path: Path, target: str, with_helper: bool
) -> None:
executable = tmp_path / f"dsh-jsonrpc-agent-pkg-{target}"
executable.write_bytes(b"runtime")
executable.chmod(0o755)
expected = {executable.name: b"runtime"}
if with_helper:
spawn_helper = Path(f"{executable}-spawn-helper")
spawn_helper.write_bytes(b"helper")
spawn_helper.chmod(0o755)
expected[spawn_helper.name] = b"helper"
destination = tmp_path / "staging"
build_python_release.stage_runtime(destination, "1.2.3", executable, executable.name)
runtime_dir = destination / "src" / "deepseek_harness_runtime" / "runtime"
assert {path.name: path.read_bytes() for path in runtime_dir.glob("dsh-jsonrpc-agent-pkg-*")} == expected