fix(account,models): reconcile provider lifecycle with master
This commit is contained in:
commit
6ef32577a3
3271 files changed
+111666
-48764
No files matched your search
@@ -26,16 +26,22 @@ class MockCompletionHandler(BaseHTTPRequestHandler):
|
||||
body = self.rfile.read(length).decode("utf-8")
|
||||
self.requests.append({
|
||||
"path": self.path,
|
||||
"authorization": self.headers.get("authorization"),
|
||||
"api_key": self.headers.get("x-api-key"),
|
||||
"body": json.loads(body),
|
||||
})
|
||||
self.send_response(200)
|
||||
self.send_header("content-type", "text/event-stream")
|
||||
self.end_headers()
|
||||
self.wfile.write(b'data: {"choices":[{"delta":{"role":"assistant","content":null,"reasoning_content":""}}]}\n\n')
|
||||
self.wfile.write(b'data: {"choices":[{"delta":{"content":"SDK runtime reached the configured HTTP model endpoint."}}]}\n\n')
|
||||
self.wfile.write(b'data: {"choices":[{"delta":{"content":""},"finish_reason":"stop"}],"usage":{"prompt_tokens":7,"completion_tokens":9}}\n\n')
|
||||
self.wfile.write(b"data: [DONE]\n\n")
|
||||
events = [
|
||||
{"type": "message_start", "message": {"id": "sdk-smoke", "model": "sdk-smoke-model", "usage": {"input_tokens": 7, "output_tokens": 0}}},
|
||||
{"type": "content_block_start", "index": 0, "content_block": {"type": "text", "text": ""}},
|
||||
{"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": "SDK runtime reached the configured HTTP model endpoint."}},
|
||||
{"type": "content_block_stop", "index": 0},
|
||||
{"type": "message_delta", "delta": {"stop_reason": "end_turn"}, "usage": {"output_tokens": 9}},
|
||||
{"type": "message_stop"},
|
||||
]
|
||||
for event in events:
|
||||
self.wfile.write(f"event: {event['type']}\ndata: {json.dumps(event)}\n\n".encode())
|
||||
|
||||
def log_message(self, _format: str, *_args: object) -> None:
|
||||
return
|
||||
@@ -46,7 +52,7 @@ def run_smoke(repo_root: Path, keep_sessions: bool) -> None:
|
||||
session_root = dsh_home / "sessions"
|
||||
runtime_entry = repo_root / "apps/cli/src/bin.ts"
|
||||
server = ThreadingHTTPServer(("127.0.0.1", 0), MockCompletionHandler)
|
||||
thread = threading.Thread(target=server.serve_forever, name="mock-openai-compatible-server", daemon=True)
|
||||
thread = threading.Thread(target=server.serve_forever, name="mock-messages-server", daemon=True)
|
||||
thread.start()
|
||||
base_url = f"http://127.0.0.1:{server.server_address[1]}"
|
||||
|
||||
@@ -86,7 +92,8 @@ def run_smoke(repo_root: Path, keep_sessions: bool) -> None:
|
||||
assert len(MockCompletionHandler.requests) == 1
|
||||
request = MockCompletionHandler.requests[0]
|
||||
print(json.dumps(request, ensure_ascii=False, indent=2)[:4000])
|
||||
assert request["authorization"] == "Bearer sdk-smoke-key"
|
||||
assert request["path"] == "/v1/messages"
|
||||
assert request["api_key"] == "sdk-smoke-key"
|
||||
assert request["body"]["model"] == "sdk-smoke-model"
|
||||
|
||||
jsonl_files = sorted(session_root.rglob("*.jsonl.zstd"))
|
||||
|
||||
@@ -595,6 +595,15 @@ def test_client_keeps_unmatched_notifications_available_globally_while_subscribe
|
||||
def test_session_subscription_keeps_descendant_relationships_across_subscriptions() -> None:
|
||||
client = HarnessClient()
|
||||
with client.subscribe_session_notifications("main") as first:
|
||||
unknown_child = {
|
||||
"type": "subagent/catalog", "seq": 0, "time": 1,
|
||||
"data": {"version": 1, "childId": "unreadable-child", "childCreatedAt": 1, "mode": "unknown"},
|
||||
}
|
||||
client._handle_message({
|
||||
"jsonrpc": "2.0", "method": "session.event",
|
||||
"params": {"sessionId": "main", "event": unknown_child},
|
||||
})
|
||||
assert first.next().payload == {"sessionId": "main", "event": unknown_child}
|
||||
client._handle_message({
|
||||
"jsonrpc": "2.0",
|
||||
"method": "subagent.started",
|
||||
|
||||
@@ -26,6 +26,18 @@ def test_release_tag_is_optional_for_non_release_builds() -> None:
|
||||
build_python_release.validate_release_tag(None, "1.2.3")
|
||||
|
||||
|
||||
def test_wheel_verification_uses_distribution_metadata_not_nested_libraries(tmp_path: Path) -> None:
|
||||
wheel = tmp_path / "sdk.whl"
|
||||
with zipfile.ZipFile(wheel, "w") as archive:
|
||||
archive.writestr("nested/library.dist-info/WHEEL", "Tag: cp312-cp312-linux_x86_64\n")
|
||||
archive.writestr("nested/library.dist-info/METADATA", "Name: library\nVersion: 0.0.1\n")
|
||||
archive.writestr("deepseek_harness_sdk-1.2.3.dist-info/WHEEL", "Tag: py3-none-any\n")
|
||||
archive.writestr("deepseek_harness_sdk-1.2.3.dist-info/METADATA",
|
||||
"Name: deepseek-harness-sdk\nVersion: 1.2.3\nLicense-Expression: MIT\n"
|
||||
"License-File: LICENSE\nRequires-Dist: deepseek-harness-runtime-bin==1.2.3\n")
|
||||
build_python_release.verify_wheel(wheel, "sdk", "1.2.3", None)
|
||||
|
||||
|
||||
def test_release_tag_must_match_repository_version() -> None:
|
||||
build_python_release.validate_release_tag("python-v1.2.3", "1.2.3")
|
||||
|
||||
@@ -96,6 +108,19 @@ def test_stage_sdk_keeps_distribution_module_and_runtime_pin_distinct(tmp_path:
|
||||
assert (destination / "src" / "deepseek_harness" / "__init__.py").is_file()
|
||||
|
||||
|
||||
def test_copy_package_omits_generated_carriers_before_staging_one_target(tmp_path: Path) -> None:
|
||||
source = tmp_path / "source"
|
||||
module = source / "src/deepseek_harness_runtime"
|
||||
for path in ("runtime/macos-arm64/primary-runtime/runtime.json", "runtime/node/package.json",
|
||||
"runtime/deepseek-harness-sdk-runtime-win-x64.exe", "__init__.py", "_resources.py"):
|
||||
file = module / path
|
||||
file.parent.mkdir(parents=True, exist_ok=True)
|
||||
file.touch()
|
||||
destination = tmp_path / "staged"
|
||||
build_python_release.copy_package(source, destination)
|
||||
assert sorted(path.name for path in (destination / "src/deepseek_harness_runtime").iterdir()) == ["__init__.py", "_resources.py"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("target", "with_helper"),
|
||||
[("linux-x64", False), ("macos-arm64", True), ("macos-x64", True), ("win-x64.exe", False)],
|
||||
@@ -124,6 +149,10 @@ def test_stage_runtime_copies_platform_payload(
|
||||
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")
|
||||
resources = executable.with_name(executable.name.removeprefix("deepseek-harness-sdk-runtime-").removesuffix(".exe"))
|
||||
resource = resources / "office-skills/scripts/check_office.py"
|
||||
resource.parent.mkdir(parents=True)
|
||||
resource.write_text("checker")
|
||||
destination = tmp_path / "staging"
|
||||
|
||||
build_python_release.stage_runtime(destination, "1.2.3", executable, executable.name)
|
||||
@@ -135,6 +164,7 @@ def test_stage_runtime_copies_platform_payload(
|
||||
if path.is_file()
|
||||
} == expected
|
||||
assert (runtime_dir / office.name / office_asset.relative_to(office)).read_bytes() == b"office data"
|
||||
assert (runtime_dir / resources.name / resource.relative_to(resources)).read_text() == "checker"
|
||||
pyproject = (destination / "pyproject.toml").read_text()
|
||||
assert 'license = "MIT"' in pyproject
|
||||
assert 'license-files = ["LICENSE", "THIRD_PARTY_NOTICES.md"]' in pyproject
|
||||
|
||||
@@ -6,11 +6,13 @@ import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
import deepseek_harness_runtime as runtime
|
||||
import pytest
|
||||
from deepseek_harness_runtime._resources import validate_resources
|
||||
|
||||
from deepseek_harness_runtime import (
|
||||
RUNTIME_MODE_ENV_VAR,
|
||||
@@ -20,7 +22,7 @@ from deepseek_harness_runtime import (
|
||||
)
|
||||
|
||||
|
||||
def _office_sidecar(executable: Path, native_targets: tuple[str, ...] = ("darwin-arm64", "darwin-x64", "win32-x64")) -> Path:
|
||||
def _resource_sidecars(executable: Path, native_targets: tuple[str, ...] = ("darwin-arm64", "darwin-x64", "win32-x64")) -> Path:
|
||||
office = executable.with_name(f"{executable.name.removesuffix('.exe')}-office")
|
||||
tag = executable.name.removeprefix("deepseek-harness-sdk-runtime-").removesuffix(".exe")
|
||||
native = tag.replace("win-", "win32-").replace("macos-", "darwin-")
|
||||
@@ -33,6 +35,21 @@ def _office_sidecar(executable: Path, native_targets: tuple[str, ...] = ("darwin
|
||||
adapter.write_text(json.dumps({"optionalDependencies": {
|
||||
f"@deepseek-ai/libreoffice-kit-{target}": "0.0.1" for target in (*native_targets, "wasm")
|
||||
}}), encoding="utf-8")
|
||||
resources = executable.with_name(tag)
|
||||
manifest = resources / "primary-runtime/runtime.json"
|
||||
manifest.parent.mkdir(parents=True)
|
||||
manifest.write_text(json.dumps({"platform": native.rsplit("-", 1)[0], "arch": tag.rsplit("-", 1)[1],
|
||||
"python": "3.12.14", "pythonPackages": {"numpy": "2.3.5"}}))
|
||||
python = resources / "primary-runtime/dependencies/python" / ("python.exe" if tag.startswith("win-") else "bin/python3")
|
||||
python.parent.mkdir(parents=True)
|
||||
python.touch()
|
||||
python.chmod(0o755)
|
||||
packages = python.parent if tag.startswith("win-") else python.parent.parent
|
||||
(packages / ("Lib/site-packages" if tag.startswith("win-") else "lib/python3.12/site-packages")).mkdir(parents=True)
|
||||
for file in ["scripts/check_office.py", *(f"office-{kind}/SKILL.md" for kind in ("docx", "pptx", "xlsx"))]:
|
||||
path = resources / "office-skills" / file
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.touch()
|
||||
return office
|
||||
|
||||
|
||||
@@ -41,6 +58,43 @@ def test_unknown_explicit_mode_fails_loud() -> None:
|
||||
resolve_bundled_launch_args("bogus")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("target", ["linux-x64", "linux-arm64", "macos-arm64", "macos-x64", "win-x64"])
|
||||
@pytest.mark.parametrize("invalid", [None, "manifest", "platform", "python", "skills", "packages", "mode"])
|
||||
def test_authoring_resources_validate_installed_and_wheel_payloads(tmp_path: Path, target: str, invalid: str | None) -> None:
|
||||
executable = tmp_path / f"deepseek-harness-sdk-runtime-{target}"
|
||||
_resource_sidecars(executable)
|
||||
root = tmp_path / target
|
||||
python = root / "primary-runtime/dependencies/python" / ("python.exe" if target == "win-x64" else "bin/python3")
|
||||
if invalid == "mode" and target == "win-x64":
|
||||
pytest.skip("Windows executables do not require a POSIX executable bit")
|
||||
if invalid == "manifest":
|
||||
(root / "primary-runtime/runtime.json").unlink()
|
||||
elif invalid == "platform":
|
||||
manifest_path = root / "primary-runtime/runtime.json"
|
||||
manifest = json.loads(manifest_path.read_text())
|
||||
manifest["arch"] = "wrong"
|
||||
manifest_path.write_text(json.dumps(manifest))
|
||||
elif invalid == "python":
|
||||
python.unlink()
|
||||
elif invalid == "skills":
|
||||
(root / "office-skills/office-docx/SKILL.md").unlink()
|
||||
elif invalid == "packages":
|
||||
next(root.rglob("site-packages")).rmdir()
|
||||
elif invalid == "mode":
|
||||
python.chmod(0o644)
|
||||
archive_path = tmp_path / "payload.zip"
|
||||
with zipfile.ZipFile(archive_path, "w") as archive:
|
||||
for path in root.rglob("*"):
|
||||
archive.write(path, str(path.relative_to(root)).replace("\\", "/"))
|
||||
with zipfile.ZipFile(archive_path) as archive:
|
||||
for candidate in (root, zipfile.Path(archive)):
|
||||
if invalid is None:
|
||||
validate_resources(candidate, target)
|
||||
else:
|
||||
with pytest.raises((ValueError, FileNotFoundError)):
|
||||
validate_resources(candidate, target)
|
||||
|
||||
|
||||
def test_unknown_env_mode_fails_loud(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv(RUNTIME_MODE_ENV_VAR, "bogus")
|
||||
with pytest.raises(ValueError, match="expected 'exe' or 'node'"):
|
||||
@@ -64,7 +118,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)
|
||||
_resource_sidecars(linux)
|
||||
macos = runtime_dir / "deepseek-harness-sdk-runtime-macos-arm64"
|
||||
macos.touch()
|
||||
Path(f"{macos}-rg").touch()
|
||||
@@ -85,7 +139,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)
|
||||
_resource_sidecars(executable)
|
||||
monkeypatch.setattr(runtime, "bundled_package_dir", lambda: tmp_path)
|
||||
monkeypatch.setattr(runtime, "_current_platform_tag", lambda: "win-x64")
|
||||
|
||||
@@ -122,7 +176,7 @@ def test_runtime_requires_ripgrep_sidecar(
|
||||
runtime.bundled_runtime_path()
|
||||
|
||||
|
||||
def test_runtime_requires_complete_office_sidecar(
|
||||
def test_runtime_requires_complete_resource_sidecars(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
executable = tmp_path / "runtime" / "deepseek-harness-sdk-runtime-linux-x64"
|
||||
@@ -134,7 +188,7 @@ def test_runtime_requires_complete_office_sidecar(
|
||||
|
||||
with pytest.raises(FileNotFoundError, match="Office sidecar"):
|
||||
runtime.bundled_runtime_path()
|
||||
office = _office_sidecar(executable)
|
||||
office = _resource_sidecars(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"):
|
||||
@@ -250,7 +304,7 @@ def test_runtime_requires_its_platform_office_engine(
|
||||
executable.with_name(f"{executable.stem}-rg{extension}").touch()
|
||||
if target.startswith("macos-"):
|
||||
Path(f"{executable}-spawn-helper").touch()
|
||||
office = _office_sidecar(executable, native_targets)
|
||||
office = _resource_sidecars(executable, native_targets)
|
||||
monkeypatch.setattr(runtime, "bundled_package_dir", lambda: tmp_path)
|
||||
monkeypatch.setattr(runtime, "_current_platform_tag", lambda: target)
|
||||
assert runtime.bundled_runtime_path() == executable
|
||||
|
||||
Reference in new issue
Block a user