Merge master after validating subagent cleanup

This commit is contained in:
Dudu-0223 committed 2026-09-20 17:59:25 +08:00
commit 703bf4d504
107 files changed
+2618 -834

No files matched your search

+81 -5
View File
@@ -44,6 +44,7 @@ MCP_TEXT = "MCP client smoke ok"
PROFILE_PLUGIN_PROMPT = "Verify the Python-installed dsh profile plugin."
PROFILE_PLUGIN_TEXT = "profile plugin smoke ok"
PROFILE_PLUGIN_MARKER = "PYTHON_INSTALLED_DSH_PROFILE_PLUGIN"
AUTHORING_PROMPT = "Query the packaged Python environment for Office authoring."
IS_WINDOWS = sys.platform == "win32"
MINIMAL_SHELL_TOOL = "pwsh" if IS_WINDOWS else "bash"
MINIMAL_SHELL_COMMAND = (
@@ -77,6 +78,8 @@ LEGACY_CUSTOM_DISABLED_ROWS = (
"plan-mode",
"skill",
"skill-filesystem",
"skill-office",
"workspace-dependencies",
"tool-fs",
"tool-fs-search",
"tool-goal",
@@ -320,6 +323,10 @@ def completion_chunks(body: dict[str, object]) -> list[dict[str, object]]:
result = tool_results[-1]
call_id, tool_name = latest_tool_call(messages, result.get("tool_use_id"))
tool_text = message_text(result.get("content"))
if tool_name == "load_workspace_dependencies":
if result.get("is_error") or "python" not in json.loads(tool_text):
raise AssertionError(f"packaged Python query failed: {tool_text}")
return text_chunks(EXPECTED_TEXT)
mcp = mcp_tool_followup(call_id, tool_name, tool_text)
if mcp is not None:
return mcp
@@ -371,6 +378,7 @@ def completion_chunks(body: dict[str, object]) -> list[dict[str, object]]:
RESTART_FIRST_PROMPT,
RESTART_SECOND_PROMPT,
PROFILE_PLUGIN_PROMPT,
AUTHORING_PROMPT,
}
prompt = next(
(candidate for candidate in user_prompts if candidate in scenario_prompts),
@@ -378,6 +386,9 @@ def completion_chunks(body: dict[str, object]) -> list[dict[str, object]]:
)
if prompt == SNAPSHOT_DIRECT_CHILD_PROMPT:
return text_chunks("DIRECT_CHILD_OK")
if prompt == AUTHORING_PROMPT:
assert_advertised_tool(body, "load_workspace_dependencies")
return tool_call_chunks("authoring-runtime", "load_workspace_dependencies", {})
if prompt == SNAPSHOT_WORKFLOW_CHILD_PROMPT:
return text_chunks("WORKFLOW_CHILD_OK")
if prompt == SNAPSHOT_PROMPT:
@@ -716,7 +727,7 @@ def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"--scenario",
choices=("all", "sdk-default", "sdk-custom", "sdk-minimal", "sdk-minimal-in-history", "sdk-fs-search", "sdk-spawn-node", "sdk-mcp", "sdk-snapshot", "sdk-restart", "sdk-profile-plugin", "sdk-office", "sdk-live", "runner", "direct"),
choices=("all", "sdk-default", "sdk-custom", "sdk-minimal", "sdk-minimal-in-history", "sdk-fs-search", "sdk-spawn-node", "sdk-mcp", "sdk-snapshot", "sdk-restart", "sdk-profile-plugin", "sdk-office", "sdk-authoring", "sdk-live", "runner", "direct"),
default="all",
)
parser.add_argument("--exe", type=Path)
@@ -735,10 +746,10 @@ def main() -> None:
parser.error("--scenario sdk-profile-plugin requires --installed-wheel")
if args.installed_wheel:
args.exe = assert_installed_wheel_environment()
if args.scenario in {"all", "sdk-custom", "sdk-minimal", "sdk-minimal-in-history", "sdk-fs-search", "sdk-spawn-node", "sdk-snapshot", "sdk-restart", "sdk-office", "runner", "direct"} and args.exe is None:
if args.scenario in {"all", "sdk-custom", "sdk-minimal", "sdk-minimal-in-history", "sdk-fs-search", "sdk-spawn-node", "sdk-snapshot", "sdk-restart", "sdk-office", "sdk-authoring", "runner", "direct"} and args.exe is None:
parser.error("--exe is required for custom, minimal, fs-search, spawn-node, snapshot, restart, office, runner, and direct scenarios")
if args.update_snapshots and args.scenario not in {"all", "sdk-minimal", "sdk-minimal-in-history", "sdk-snapshot", "sdk-restart"}:
parser.error("--update-snapshots requires --scenario sdk-minimal, sdk-minimal-in-history, sdk-snapshot, sdk-restart, or all")
if args.update_snapshots and args.scenario not in {"all", "sdk-minimal", "sdk-minimal-in-history", "sdk-snapshot", "sdk-restart", "sdk-authoring"}:
parser.error("--update-snapshots requires --scenario sdk-minimal, sdk-minimal-in-history, sdk-snapshot, sdk-restart, sdk-authoring, or all")
if args.exe is not None and not args.exe.is_file():
parser.error(f"runtime executable does not exist: {args.exe}")
@@ -762,6 +773,9 @@ def main() -> None:
return
with MockModel() as model:
if args.scenario in {"all", "sdk-authoring"}:
assert args.exe is not None
smoke_sdk_authoring(model.url, args.exe.resolve(), args.update_snapshots)
if args.scenario in {"all", "sdk-default"}:
smoke_sdk_default(model.url)
if args.scenario in {"all", "sdk-custom"}:
@@ -797,6 +811,65 @@ def main() -> None:
print(f"smoke-python-runtime: {args.scenario} passed")
def smoke_sdk_authoring(base_url: str, executable: Path, update_snapshots: bool) -> None:
"""Query the bundled Python and switch skills without replacing that environment."""
from deepseek_harness import DeepSeekHarness
resources = executable.with_name(executable.name.removeprefix("deepseek-harness-sdk-runtime-").removesuffix(".exe"))
manifest = json.loads((resources / "primary-runtime/runtime.json").read_text())
for mode in ("default", "replacement", "disabled"):
with tempfile.TemporaryDirectory(prefix="dsh-sdk-authoring-") as temporary:
root = Path(temporary).resolve()
home = root / "home"
if mode == "replacement":
skill = home / "skills/office-docx/SKILL.md"
skill.parent.mkdir(parents=True)
skill.write_text("---\nname: office-docx\ndescription: CUSTOM_OFFICE_DOCX\n---\nUse the bundled Python for custom document work.\n")
patch = root / "skills.patch.yml"
patch.write_text(json.dumps([{"id": "skill-office", "disabled": True}] if mode == "disabled" else []))
first = len(MockModelHandler.requests)
with DeepSeekHarness(
provider="deepseek-official", model="smoke-model", cwd=str(root),
dsh_bin=str(executable), dsh_home=str(home), patches=(str(patch),),
api_key="sk-keyless-smoke", base_url=base_url,
env={"DSH_PERMISSION_MODE": "danger-full-access", "DSH_TELEMETRY_DISABLED": "1"},
request_timeout_seconds=60,
) as harness:
result = harness.run(AUTHORING_PROMPT, session_id="authoring")
assert result.final_response == EXPECTED_TEXT, result.final_response
requests = MockModelHandler.requests[first:]
assert len(requests) == 2, requests
prompt = json.dumps(requests[0], ensure_ascii=False)
for name in ("office-docx", "office-pptx", "office-xlsx"):
assert (name in prompt) == (mode != "disabled"), (mode, name)
assert ("CUSTOM_OFFICE_DOCX" in prompt) == (mode == "replacement"), mode
tool_result = next(block for message in requests[1]["messages"]
for block in message.get("content", [])
if isinstance(block, dict) and block.get("tool_use_id") == "authoring-runtime")
dependencies = json.loads(message_text(tool_result["content"]))
python = Path(dependencies["python"])
assert python.is_relative_to(resources), dependencies
assert "node" not in dependencies and "pnpm" not in dependencies, dependencies
assert dependencies["pythonDistributions"] == manifest["pythonPackages"], dependencies
assert not (home / "dsh-runtimes").exists()
if mode == "default":
subprocess.run([
str(python), "-I", "-B", str(Path(__file__).parent / "primary-runtime/smoke.py"),
json.dumps(manifest["pythonPackages"]), manifest["python"],
str(resources / "office-skills/scripts/check_office.py"),
], check=True, timeout=120,
env={name: value for name, value in os.environ.items()
if not re.search(r"KEY|SECRET|TOKEN|PASSWORD", name, re.I)})
schema = next(tool for tool in requests[0]["tools"] if tool.get("name") == "load_workspace_dependencies")
visible = {"tool": schema, "result": {**dependencies, "python": "{{python}}", "pythonPackages": "{{site-packages}}"}}
compare_snapshot_files(
{"model-visible.json": json.dumps(visible, indent=2, ensure_ascii=False) + "\n"},
update_snapshots, Path(__file__).parent / "snapshots/python-sdk-single-exe/authoring",
("model-visible.json",),
)
print("smoke-python-runtime: bundled Python, default skills, replacement and disabled skills passed")
def smoke_sdk_office(executable: Path) -> None:
"""Relocate the wheel payload and convert a real DOCX with the target platform engine."""
from deepseek_harness import DeepSeekHarness
@@ -805,7 +878,8 @@ def smoke_sdk_office(executable: Path) -> None:
root = Path(temporary).resolve()
relocated = root / executable.name
stem = executable.name.removesuffix(".exe")
for source in executable.parent.glob(f"{stem}*"):
resources = executable.with_name(stem.removeprefix("deepseek-harness-sdk-runtime-"))
for source in [*executable.parent.glob(f"{stem}*"), resources]:
destination = root / source.name
if source.is_dir():
shutil.copytree(source, destination)
@@ -850,6 +924,8 @@ def smoke_sdk_office(executable: Path) -> None:
api_key="sk-keyless-smoke",
base_url="http://127.0.0.1:9",
env={"DSH_PERMISSION_MODE": "danger-full-access", "DSH_TELEMETRY_DISABLED": "1"},
# The startup plugin awaits a converter with a 120-second deadline before JSON-RPC is ready.
initialize_timeout_seconds=180,
request_timeout_seconds=180,
):
pass