cleanup(build): collapse native runtime payloads

This commit is contained in:
Tianyi Cui
2026-07-30 01:09:54 +08:00
parent 0e53b7a8aa
commit 7118b4cfe1
4 changed files with 60 additions and 139 deletions
+9 -16
View File
@@ -39,31 +39,24 @@ class RuntimeBuildHook(BuildHookInterface):
)
platform_tag = os.environ.get("DSH_RUNTIME_PLATFORM_TAG") or _host_platform_tag()
matches = [(key, value) for key, value in _PLATFORMS.items() if value[0] == platform_tag]
matches = [value for value in _PLATFORMS.values() if value[0] == platform_tag]
if len(matches) != 1:
supported = ", ".join(value[0] for value in _PLATFORMS.values())
raise RuntimeError(
f"unsupported DSH_RUNTIME_PLATFORM_TAG {platform_tag!r}; expected one of {supported}"
)
expected_target, (_, expected_executable) = matches[0]
expected_executable = matches[0][1]
runtime_dir = Path(self.root) / "src" / "deepseek_harness_runtime" / "runtime"
runtime_files = sorted(runtime_dir.glob("dsh-jsonrpc-agent-pkg-*") if runtime_dir.is_dir() else [])
executables = [path for path in runtime_files if not path.name.endswith(_SPAWN_HELPER_SUFFIX)]
helpers = [path for path in runtime_files if path.name.endswith(_SPAWN_HELPER_SUFFIX)]
if [path.name for path in executables] != [expected_executable]:
found = ", ".join(path.name for path in executables) or "none"
expected_files = [expected_executable]
if "-macos-" in expected_executable:
expected_files.append(f"{expected_executable}{_SPAWN_HELPER_SUFFIX}")
found_files = [path.name for path in runtime_files]
if found_files != expected_files:
raise RuntimeError(
f"runtime wheel {platform_tag} must contain only {expected_executable}; found {found}"
f"runtime wheel {platform_tag} payload must be {expected_files}; found {found_files}"
)
expected_helper = f"{expected_executable}{_SPAWN_HELPER_SUFFIX}"
expected_helpers = [expected_helper] if expected_target.startswith("macos-") else []
if [path.name for path in helpers] != expected_helpers:
expected = ", ".join(expected_helpers) or "none"
found = ", ".join(path.name for path in helpers) or "none"
raise RuntimeError(
f"runtime wheel {platform_tag} helper payload mismatch: expected {expected}; found {found}"
)
for executable in [executables[0], *helpers]:
for executable in runtime_files:
if executable.stat().st_mode & stat.S_IXUSR == 0:
raise RuntimeError(f"runtime executable is not executable: {executable}")
build_data["pure_python"] = False
+3 -27
View File
@@ -68,7 +68,7 @@ def test_stage_runtime_rejects_missing_spawn_helper(tmp_path: Path) -> None:
executable.write_bytes(b"runtime")
executable.chmod(0o755)
with pytest.raises(FileNotFoundError, match="spawn helper"):
with pytest.raises(FileNotFoundError, match="spawn-helper"):
build_python_release.stage_runtime(
tmp_path / "staging",
"1.2.3",
@@ -77,32 +77,8 @@ def test_stage_runtime_rejects_missing_spawn_helper(tmp_path: Path) -> None:
)
def test_stage_runtime_rejects_unsupported_executable_name(tmp_path: Path) -> None:
executable = tmp_path / "custom-runtime"
executable.write_bytes(b"runtime")
executable.chmod(0o755)
with pytest.raises(
ValueError,
match=(
"unsupported runtime executable 'custom-runtime'; expected one of: "
"dsh-jsonrpc-agent-pkg-linux-arm64, dsh-jsonrpc-agent-pkg-linux-x64, "
"dsh-jsonrpc-agent-pkg-macos-arm64"
),
):
build_python_release.stage_runtime(
tmp_path / "staging",
"1.2.3",
executable,
executable.name,
)
@pytest.mark.parametrize("target", ["linux-x64", "linux-arm64"])
def test_stage_runtime_copies_linux_executable_without_spawn_helper(
tmp_path: Path, target: str
) -> None:
executable = tmp_path / f"dsh-jsonrpc-agent-pkg-{target}"
def test_stage_runtime_copies_linux_executable_without_spawn_helper(tmp_path: Path) -> None:
executable = tmp_path / "dsh-jsonrpc-agent-pkg-linux-x64"
executable.write_bytes(b"runtime")
executable.chmod(0o755)
destination = tmp_path / "staging"