Merge remote-tracking branch 'origin/master' into release/session-log-v3

This commit is contained in:
Tianyi Cui
2026-09-06 20:20:16 +08:00
57 changed files with 1405 additions and 67 deletions
+2 -2
View File
@@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write python/sdk-runtime/README.md
README.md: 050ae85d9b0a38b82a3c66a84c3d8f34e137be6c
README.zh.md: 7066d7224752294c25b58cfe8fb6a94524a2013d
README.md: fb7478f305015e60dafd23861ab6fd91f10757f3
README.zh.md: 7c663aba8d387fb7b1048afe28d50faee7350303
+1 -1
View File
@@ -19,7 +19,7 @@ Both carriers execute the same `dsh` grammar and shipped profiles, including the
- `bundled_package_dir() -> Path` returns the installed module-data root and verifies its release metadata.
- `bundled_runtime_path() -> Path` returns the current platform executable and verifies required sidecars.
- `resolve_bundled_launch_args(mode=None) -> tuple[str, ...]` returns the executable argv by default. Explicit `mode="node"` or `DSH_RUNTIME_MODE=node` selects the repo-only Node carrier.
- `main()` implements the installed `dsh` console command and rejects an absent or blank `DSH_HOME` before replacing the Python process.
- `main()` implements the installed `dsh` console command and rejects an absent or blank `DSH_HOME`. On Windows it waits for the bundled process with inherited standard streams and forwards its exit status; on POSIX it replaces the Python process.
Unsupported platforms and missing executables or sidecars raise `FileNotFoundError` with the build and installation routes. Unknown runtime modes raise `ValueError`.
+1 -1
View File
@@ -19,7 +19,7 @@ Wheel 会安装 `dsh` 控制台命令和 `deepseek_harness_runtime` Python 模
- `bundled_package_dir() -> Path` 返回已安装模块数据根目录,并校验发布元数据。
- `bundled_runtime_path() -> Path` 返回当前平台可执行程序,并校验必需伴随文件。
- `resolve_bundled_launch_args(mode=None) -> tuple[str, ...]` 默认返回可执行程序 argv。显式 `mode="node"``DSH_RUNTIME_MODE=node` 会选择仅限仓库使用的 Node 载体。
- `main()` 实现已安装的 `dsh` 控制台命令,并在替换 Python 进程前拒绝缺失或空白的 `DSH_HOME`
- `main()` 实现已安装的 `dsh` 控制台命令,并拒绝缺失或空白的 `DSH_HOME`在 Windows 上,它让打包进程继承标准流,等待其结束并转发退出状态;在 POSIX 上,它替换 Python 进程。
不支持的平台以及缺失的可执行程序或伴随文件会抛出 `FileNotFoundError`,并指出构建与安装路径。未知运行时模式会抛出 `ValueError`
@@ -24,6 +24,7 @@ from __future__ import annotations
import os
import platform
import shutil
import subprocess
import sys
from pathlib import Path
@@ -156,7 +157,7 @@ def _node_launch_args() -> tuple[str, str]:
def main() -> None:
"""Execute the bundled dsh CLI with an explicitly selected Harness home."""
"""Launch the CLI with explicit DSH_HOME; wait on Windows, replace the process on POSIX."""
if not os.environ.get("DSH_HOME", "").strip():
print(
"dsh: the Python runtime command requires an explicit DSH_HOME; "
@@ -165,6 +166,9 @@ def main() -> None:
)
raise SystemExit(2)
argv = (*resolve_bundled_launch_args(), *sys.argv[1:])
if sys.platform == "win32":
# Windows CRT exec does not replace the process; wait and preserve the runtime status.
raise SystemExit(subprocess.run(argv, env=os.environ).returncode)
os.execvpe(argv[0], argv, os.environ)
+53 -1
View File
@@ -2,7 +2,11 @@
from __future__ import annotations
import os
import subprocess
import sys
from pathlib import Path
from types import SimpleNamespace
import deepseek_harness_runtime as runtime
import pytest
@@ -129,7 +133,7 @@ def test_python_dsh_command_executes_the_bundled_cli(
called: dict[str, object] = {}
monkeypatch.setenv("DSH_HOME", "/explicit/home")
monkeypatch.setattr(runtime, "resolve_bundled_launch_args", lambda: ("/runtime",))
monkeypatch.setattr(runtime.sys, "argv", ["dsh", "plugin", "--profile", "sdk", "list"])
monkeypatch.setattr(runtime, "sys", SimpleNamespace(platform="linux", argv=["dsh", "plugin", "--profile", "sdk", "list"]))
def execvpe(file: str, args: tuple[str, ...], env: dict[str, str]) -> None:
called.update(file=file, args=args, home=env.get("DSH_HOME"))
@@ -143,3 +147,51 @@ def test_python_dsh_command_executes_the_bundled_cli(
"args": ("/runtime", "plugin", "--profile", "sdk", "list"),
"home": "/explicit/home",
}
@pytest.mark.parametrize("returncode", [0, 37, 513])
def test_windows_console_waits_and_forwards_runtime_status(monkeypatch: pytest.MonkeyPatch, returncode: int) -> None:
monkeypatch.setenv("DSH_HOME", "/explicit/home")
monkeypatch.setattr(runtime, "sys", SimpleNamespace(platform="win32", argv=["dsh", "plugin", "argument with spaces", "中文"]))
monkeypatch.setattr(runtime, "resolve_bundled_launch_args", lambda: ("runtime.exe",))
called = []
def run(args: tuple[str, ...], **kwargs: object) -> subprocess.CompletedProcess[str]:
called.append((args, kwargs))
return subprocess.CompletedProcess(args, returncode)
def forbidden_exec(*args: object) -> None:
pytest.fail("Windows console must wait instead of entering CRT exec")
monkeypatch.setattr(subprocess, "run", run)
monkeypatch.setattr(runtime.os, "execvpe", forbidden_exec)
with pytest.raises(SystemExit) as result:
main()
assert result.value.code == returncode
assert called == [(("runtime.exe", "plugin", "argument with spaces", "中文"), {"env": os.environ})]
@pytest.mark.parametrize("returncode", [0, 37, pytest.param(513, marks=pytest.mark.skipif(sys.platform != "win32", reason="POSIX truncates process exit codes to eight bits"))])
def test_windows_console_branch_preserves_real_child_io_and_completion(tmp_path: Path, returncode: int) -> None:
child = tmp_path / "child with spaces.py"
sentinel = tmp_path / "finished"
child.write_text(
"import pathlib,sys\n"
"assert sys.argv[1] == 'argument with spaces'\n"
"assert sys.argv[2] == '中文'\n"
"print('stdout-中文', flush=True)\n"
"print('stderr-中文', file=sys.stderr, flush=True)\n"
f"pathlib.Path({str(sentinel)!r}).write_text('done')\n"
f"raise SystemExit({returncode})\n", encoding="utf-8",
)
driver = (
"import deepseek_harness_runtime as runtime; from types import SimpleNamespace; "
f"runtime.sys = SimpleNamespace(platform='win32', argv=['dsh', 'argument with spaces', '中文']); "
f"runtime.resolve_bundled_launch_args = lambda: ({sys.executable!r}, {str(child)!r}); runtime.main()"
)
result = subprocess.run([sys.executable, "-c", driver], capture_output=True, text=True, encoding="utf-8",
env={**os.environ, "DSH_HOME": str(tmp_path), "PYTHONIOENCODING": "utf-8"}, timeout=15)
assert result.returncode == returncode, result.stderr
assert result.stdout == "stdout-中文\n"
assert result.stderr == "stderr-中文\n"
assert sentinel.read_text() == "done"
+15
View File
@@ -2,6 +2,7 @@ from __future__ import annotations
import json
import runpy
import subprocess
from pathlib import Path
import pytest
@@ -331,3 +332,17 @@ def test_snapshot_generation_filename_must_match_header(tmp_path: Path) -> None:
with pytest.raises(AssertionError, match="filename declares Session format v1"):
SMOKE["selected_snapshot_session_files"](tmp_path)
@pytest.mark.parametrize("returncode", [1, -1073741819, 3221225477])
def test_profile_plugin_failure_reports_native_exit_status(monkeypatch: pytest.MonkeyPatch, returncode: int) -> None:
def failed_install(*args: object, **kwargs: object) -> subprocess.CompletedProcess[str]:
return subprocess.CompletedProcess(args=[], returncode=returncode, stdout="", stderr="")
monkeypatch.setattr(subprocess, "run", failed_install)
with pytest.raises(AssertionError) as error:
SMOKE["smoke_sdk_profile_plugin"]("http://127.0.0.1:1")
message = str(error.value)
assert f"returncode={returncode}" in message
assert f"0x{returncode & 0xffffffff:08x}" in message
assert "stdout='' stderr=''" in message