feat(document): decouple shared Office conversion from preview
This commit is contained in:
1 parent
e7a4621aa9
commit
9d2a3bf2b7
109 files changed
+3617
-70
No files matched your search
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
import runpy
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
@@ -119,6 +120,10 @@ def test_stage_runtime_copies_platform_payload(
|
||||
spawn_helper.write_bytes(b"helper")
|
||||
spawn_helper.chmod(0o755)
|
||||
expected[spawn_helper.name] = b"helper"
|
||||
office = executable.parent / build_python_release.office_sidecar_name(executable.name)
|
||||
office_asset = office / "node_modules" / "@deepseek-ai" / "libreoffice-kit-wasm" / "assets" / "soffice.data"
|
||||
office_asset.parent.mkdir(parents=True)
|
||||
office_asset.write_bytes(b"office data")
|
||||
destination = tmp_path / "staging"
|
||||
|
||||
build_python_release.stage_runtime(destination, "1.2.3", executable, executable.name)
|
||||
@@ -127,7 +132,9 @@ def test_stage_runtime_copies_platform_payload(
|
||||
assert {
|
||||
path.name: path.read_bytes()
|
||||
for path in runtime_dir.glob("deepseek-harness-sdk-runtime-*")
|
||||
if path.is_file()
|
||||
} == expected
|
||||
assert (runtime_dir / office.name / office_asset.relative_to(office)).read_bytes() == b"office data"
|
||||
pyproject = (destination / "pyproject.toml").read_text()
|
||||
assert 'license = "MIT"' in pyproject
|
||||
assert 'license-files = ["LICENSE", "THIRD_PARTY_NOTICES.md"]' in pyproject
|
||||
@@ -152,3 +159,42 @@ def test_stage_runtime_rejects_a_noncanonical_executable_name(tmp_path: Path) ->
|
||||
executable,
|
||||
"deepseek-harness-sdk-runtime-win-x64.exe",
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("platform_tag,selected", [
|
||||
("manylinux_2_28_x86_64", "wasm"), ("macosx_14_0_arm64", "darwin-arm64"),
|
||||
("macosx_14_0_x86_64", "darwin-x64"), ("win_amd64", "win32-x64"),
|
||||
])
|
||||
@pytest.mark.parametrize("invalid", [None, "asset", "missing-engine", "foreign-engine", "helper-mode"])
|
||||
def test_office_wheel_requires_only_target_engine(
|
||||
tmp_path: Path, platform_tag: str, selected: str, invalid: str | None,
|
||||
) -> None:
|
||||
root = "runtime-office/node_modules"
|
||||
wheel = tmp_path / "office.zip"
|
||||
native = selected != "wasm"
|
||||
if invalid == "helper-mode" and (not native or platform_tag == "win_amd64"):
|
||||
pytest.skip("executable mode applies to POSIX native helpers")
|
||||
engine = ({"kind": "native", "executable": "bin/helper"} if native else
|
||||
{"kind": "wasm", "loader": "loader.cjs", "wasm": "engine.wasm", "data": "engine.data", "metadata": "fonts.json"})
|
||||
with zipfile.ZipFile(wheel, "w") as archive:
|
||||
archive.writestr(f"{root}/@deepseek-ai/libreoffice-kit/package.json", "{}")
|
||||
base = f"{root}/@deepseek-ai/libreoffice-kit-{selected}"
|
||||
if invalid != "missing-engine":
|
||||
archive.writestr(f"{base}/prebuilds.json", json.dumps({"engine": engine}))
|
||||
for field in (("executable",) if native else ("loader", "wasm", "data", "metadata")):
|
||||
if invalid == "asset" and field == ("executable" if native else "data"):
|
||||
continue
|
||||
asset = zipfile.ZipInfo(f"{base}/{engine[field]}")
|
||||
asset.external_attr = (0o644 if invalid == "helper-mode" else 0o755) << 16
|
||||
archive.writestr(asset, b"payload")
|
||||
if invalid == "foreign-engine":
|
||||
foreign = "wasm" if native else "darwin-arm64"
|
||||
archive.writestr(f"{root}/@deepseek-ai/libreoffice-kit-{foreign}/prebuilds.json", "{}")
|
||||
with zipfile.ZipFile(wheel) as archive:
|
||||
if invalid is None:
|
||||
build_python_release.verify_office_payload(archive, root, platform_tag)
|
||||
else:
|
||||
message = {"asset": "asset is missing", "missing-engine": "dependency is missing",
|
||||
"foreign-engine": "Unexpected Office engine", "helper-mode": "executable bit"}[invalid]
|
||||
with pytest.raises(RuntimeError, match=message):
|
||||
build_python_release.verify_office_payload(archive, root, platform_tag)
|
||||
@@ -19,6 +19,17 @@ from deepseek_harness_runtime import (
|
||||
)
|
||||
|
||||
|
||||
def _office_sidecar(executable: Path) -> Path:
|
||||
office = executable.with_name(f"{executable.name.removesuffix('.exe')}-office")
|
||||
tag = executable.name.removeprefix("deepseek-harness-sdk-runtime-").removesuffix(".exe")
|
||||
engine = "wasm" if tag.startswith("linux-") else tag.replace("win-", "win32-").replace("macos-", "darwin-")
|
||||
for required in ("@deepseek-ai/libreoffice-kit/package.json", f"@deepseek-ai/libreoffice-kit-{engine}/prebuilds.json"):
|
||||
path = office / "node_modules" / required
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text("{}")
|
||||
return office
|
||||
|
||||
|
||||
def test_unknown_explicit_mode_fails_loud() -> None:
|
||||
with pytest.raises(ValueError, match="expected 'exe' or 'node'"):
|
||||
resolve_bundled_launch_args("bogus")
|
||||
@@ -47,6 +58,7 @@ def test_runtime_requires_spawn_helper_only_on_macos(
|
||||
linux = runtime_dir / "deepseek-harness-sdk-runtime-linux-x64"
|
||||
linux.touch()
|
||||
Path(f"{linux}-rg").touch()
|
||||
_office_sidecar(linux)
|
||||
macos = runtime_dir / "deepseek-harness-sdk-runtime-macos-arm64"
|
||||
macos.touch()
|
||||
Path(f"{macos}-rg").touch()
|
||||
@@ -67,6 +79,7 @@ def test_windows_runtime_uses_exe_payload_and_exe_sidecar(
|
||||
executable = runtime_dir / "deepseek-harness-sdk-runtime-win-x64.exe"
|
||||
executable.touch()
|
||||
(runtime_dir / "deepseek-harness-sdk-runtime-win-x64-rg.exe").touch()
|
||||
_office_sidecar(executable)
|
||||
monkeypatch.setattr(runtime, "bundled_package_dir", lambda: tmp_path)
|
||||
monkeypatch.setattr(runtime, "_current_platform_tag", lambda: "win-x64")
|
||||
|
||||
@@ -103,6 +116,25 @@ def test_runtime_requires_ripgrep_sidecar(
|
||||
runtime.bundled_runtime_path()
|
||||
|
||||
|
||||
def test_runtime_requires_complete_office_sidecar(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
executable = tmp_path / "runtime" / "deepseek-harness-sdk-runtime-linux-x64"
|
||||
executable.parent.mkdir()
|
||||
executable.touch()
|
||||
Path(f"{executable}-rg").touch()
|
||||
monkeypatch.setattr(runtime, "bundled_package_dir", lambda: tmp_path)
|
||||
monkeypatch.setattr(runtime, "_current_platform_tag", lambda: "linux-x64")
|
||||
|
||||
with pytest.raises(FileNotFoundError, match="Office sidecar"):
|
||||
runtime.bundled_runtime_path()
|
||||
office = _office_sidecar(executable)
|
||||
assert runtime.bundled_runtime_path() == executable
|
||||
(office / "node_modules/@deepseek-ai/libreoffice-kit-wasm/prebuilds.json").unlink()
|
||||
with pytest.raises(FileNotFoundError, match="Office sidecar"):
|
||||
runtime.bundled_runtime_path()
|
||||
|
||||
|
||||
def test_node_mode_runs_the_deployed_dsh_cli(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
@@ -195,3 +227,25 @@ def test_windows_console_branch_preserves_real_child_io_and_completion(tmp_path:
|
||||
assert result.stdout == "stdout-中文\n"
|
||||
assert result.stderr == "stderr-中文\n"
|
||||
assert sentinel.read_text() == "done"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("target", ["linux-x64", "linux-arm64", "macos-arm64", "macos-x64", "win-x64"])
|
||||
def test_runtime_requires_its_platform_office_engine(tmp_path: Path, monkeypatch: pytest.MonkeyPatch, target: str) -> None:
|
||||
extension = ".exe" if target.startswith("win-") else ""
|
||||
executable = tmp_path / "runtime" / f"deepseek-harness-sdk-runtime-{target}{extension}"
|
||||
executable.parent.mkdir()
|
||||
executable.touch()
|
||||
executable.with_name(f"{executable.stem}-rg{extension}").touch()
|
||||
if target.startswith("macos-"):
|
||||
Path(f"{executable}-spawn-helper").touch()
|
||||
office = _office_sidecar(executable)
|
||||
monkeypatch.setattr(runtime, "bundled_package_dir", lambda: tmp_path)
|
||||
monkeypatch.setattr(runtime, "_current_platform_tag", lambda: target)
|
||||
assert runtime.bundled_runtime_path() == executable
|
||||
engine = next(office.glob("node_modules/@deepseek-ai/libreoffice-kit-*/prebuilds.json"))
|
||||
engine.unlink()
|
||||
foreign = office / "node_modules/@deepseek-ai" / ("libreoffice-kit-darwin-arm64" if target.startswith("linux-") else "libreoffice-kit-wasm") / "prebuilds.json"
|
||||
foreign.parent.mkdir(parents=True, exist_ok=True)
|
||||
foreign.write_text("{}")
|
||||
with pytest.raises(FileNotFoundError, match="Office sidecar"):
|
||||
runtime.bundled_runtime_path()
|
||||
Reference in new issue
Block a user