fix: validate optional Python resources and isolate downloads
This commit is contained in:
1 parent
305021fcd6
commit
4fd85be130
19 files changed
+335
-149
No files matched your search
@@ -28,7 +28,7 @@ import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from ._resources import validate_downloads, office_launch_args
|
||||
from ._resources import validate_downloads, validate_resources, office_launch_args
|
||||
|
||||
PACKAGE_METADATA_FILENAME = "deepseek-harness-runtime.json"
|
||||
|
||||
@@ -153,8 +153,9 @@ def _node_launch_args() -> tuple[str, str]:
|
||||
return (node, str(bin_js))
|
||||
|
||||
|
||||
def _download(flag: str) -> Path:
|
||||
result = subprocess.run((*resolve_bundled_launch_args(), flag), capture_output=True, text=True)
|
||||
def _download(resource: str) -> Path:
|
||||
result = subprocess.run(resolve_bundled_launch_args(), capture_output=True, encoding="utf-8",
|
||||
env={**os.environ, "DSH_RUNTIME_DOWNLOAD": resource})
|
||||
if result.returncode:
|
||||
raise RuntimeError(result.stderr.strip() or f"resource download failed with exit code {result.returncode}")
|
||||
path = json.loads(result.stdout)
|
||||
@@ -171,7 +172,7 @@ def download_office() -> Path:
|
||||
This explicit operation requires network access on a cache miss, not a
|
||||
Harness home, agent, or model. Other SDK operations never trigger downloads.
|
||||
"""
|
||||
return _download("--download-office")
|
||||
return _download("office")
|
||||
|
||||
|
||||
def download_primary_runtime() -> Path:
|
||||
@@ -181,7 +182,9 @@ def download_primary_runtime() -> Path:
|
||||
Office engine download and does not copy resources into a Harness home.
|
||||
Completed downloads are reused; DSH_RESOURCE_CACHE selects the cache root.
|
||||
"""
|
||||
return _download("--download-primary-runtime")
|
||||
path = _download("primary")
|
||||
validate_resources(path.parent, _current_platform_tag())
|
||||
return path
|
||||
|
||||
|
||||
def resolve_office_launch_args() -> tuple[str, str]:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""Validate the authoring resources in staged, installed, or archived runtime wheels."""
|
||||
"""Validate wheel download manifests, downloaded resources, and Office process launches."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -72,6 +72,12 @@ def office_launch_args(root: Path, target: str) -> tuple[str, str]:
|
||||
office = Path(os.environ.get("DSH_OFFICE_SIDECAR", str(cache / metadata["identity"] / "office")))
|
||||
if not office.is_absolute():
|
||||
raise ValueError("DSH_OFFICE_SIDECAR must be an absolute directory")
|
||||
if "DSH_OFFICE_SIDECAR" not in os.environ:
|
||||
complete = office / "complete"
|
||||
if not complete.is_file():
|
||||
raise FileNotFoundError(f"Office download is incomplete: {office}. Call deepseek_harness_runtime.download_office() first.")
|
||||
if complete.read_text(encoding="utf-8") != metadata["identity"]:
|
||||
raise ValueError(f"Office cache identity mismatch: {office}")
|
||||
node = office / "node/bin" / ("node.exe" if target == "win-x64" else "node")
|
||||
cli = office / "node_modules/@deepseek-ai/libreoffice-kit/lib/cli.js"
|
||||
for path in (node, cli):
|
||||
@@ -80,16 +86,16 @@ def office_launch_args(root: Path, target: str) -> tuple[str, str]:
|
||||
return str(node), str(cli)
|
||||
|
||||
|
||||
def run_office_process(arguments: Sequence[str], *, capture_output: bool) -> subprocess.CompletedProcess[bytes]:
|
||||
"""Run Office with captured or inherited streams; a second interrupt kills its process tree."""
|
||||
def run_office_process(arguments: Sequence[str]) -> subprocess.CompletedProcess[bytes]:
|
||||
"""Run Office with captured streams; a second interrupt kills its process tree."""
|
||||
taskkill = os.path.join(os.environ.get("SystemRoot", ""), "System32", "taskkill.exe")
|
||||
if os.name == "nt" and not os.path.isabs(taskkill):
|
||||
raise ValueError("Office operations on Windows require an absolute SystemRoot environment value.")
|
||||
with subprocess.Popen(
|
||||
arguments,
|
||||
stdin=subprocess.DEVNULL if capture_output else None,
|
||||
stdout=subprocess.PIPE if capture_output else None,
|
||||
stderr=subprocess.PIPE if capture_output else None,
|
||||
stdin=subprocess.DEVNULL,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
start_new_session=os.name != "nt",
|
||||
) as process:
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user