Skip to content

The agent that grows with you

fix(bot-mode): avoid selecting batch shims for literal delivery argv

funky-xamarin6c2bf8d63d6d
diff --git a/tests/tools/test_bot_delivery_install_launcher.py b/tests/tools/test_bot_delivery_install_launcher.py
index 756260c80b6..ad3516d4ea9 100644
--- a/tests/tools/test_bot_delivery_install_launcher.py
+++ b/tests/tools/test_bot_delivery_install_launcher.py
@@ -41,11 +41,10 @@ def test_unpublished_install_retains_interpreter_sibling(launchers):
@pytest.mark.platforms("windows")
-def test_windows_delivery_uses_published_cmd_when_exe_is_absent(launchers):
- published, _ = launchers
- command_file = published.with_suffix(".cmd")
- command_file.touch()
- assert bot_relay.local_delivery_command("default", "body.txt")[0] == str(command_file)
+def test_windows_delivery_does_not_select_batch_shims(launchers):
+ published, sibling = launchers
+ published.with_suffix(".cmd").touch()
+ assert bot_relay.local_delivery_command("default", "body.txt")[0] == str(sibling)
def test_path_then_bare_fallback_remain_available(launchers, monkeypatch):
@@ -58,8 +57,7 @@ def test_path_then_bare_fallback_remain_available(launchers, monkeypatch):
@pytest.mark.platforms("windows")
[email protected]("command_file", [False, True])
-def test_real_delivery_launcher_imports_new_generation(tmp_path, monkeypatch, command_file):
+def test_real_delivery_launcher_imports_new_generation(tmp_path, monkeypatch):
import json
import os
import subprocess
@@ -92,10 +90,7 @@ def test_real_delivery_launcher_imports_new_generation(tmp_path, monkeypatch, co
monkeypatch.setenv("HERMES_RUNTIME_DIR", str(runtime))
out = root / ".hermes" / "bin"
out.mkdir(parents=True)
- with monkeypatch.context() as mint_patch:
- if command_file:
- mint_patch.setattr(_launchers, "_load_script_maker", lambda: None)
- published = _launchers.mint_launcher("hermes", root, out, real_python, None)
+ published = _launchers.mint_launcher("hermes", root, out, real_python, None)
assert published is not None
record = runtime_facts_path(root)
record.parent.mkdir(parents=True, exist_ok=True)
@@ -111,7 +106,7 @@ def test_real_delivery_launcher_imports_new_generation(tmp_path, monkeypatch, co
assert _launchers.mint_launcher("hermes", old_package.parent, old_bin, real_python, None)
monkeypatch.setattr(bot_relay, "__file__", str(root / "tools" / "bot_relay.py"))
monkeypatch.setattr(sys, "executable", str(old_bin / "python.exe"))
- argv = bot_relay.local_delivery_command("researcher", "message.txt")
+ argv = bot_relay.local_delivery_command("researcher", str(tmp_path / "message&extra.txt"))
for generation in ("first", "new-plugin"):
selected = record.parent / "environments" / generation / "venv"
packages = site_packages(selected)
@@ -133,7 +128,7 @@ def test_real_delivery_launcher_imports_new_generation(tmp_path, monkeypatch, co
assert "old-generation" not in result.stdout
[email protected]("name", ["hermes", "hermes.exe", "hermes.cmd"])
[email protected]("name", ["hermes", "hermes.exe"])
def test_launcher_shape_preserves_profile_and_lock(tmp_path, monkeypatch, name):
import contextlib
from tools import bot_mode_dm, bot_mode_probe
diff --git a/tools/bot_mode_dm.py b/tools/bot_mode_dm.py
index f5b850bbb4a..2b595ac5269 100644
--- a/tools/bot_mode_dm.py
+++ b/tools/bot_mode_dm.py
@@ -407,7 +407,7 @@ def _delivery_lock(argv: list[str], *, stdin_file: bool):
# (service contexts lack PATH) and carries .exe on Windows; split on both separators.
# Split on both separators so the shape matches regardless of which platform built the argv. See #93590.
cli = (argv[0] if argv else "").rsplit("\\", 1)[-1].rsplit("/", 1)[-1]
- if stdin_file or len(argv) < 3 or cli not in ("hermes", "hermes.exe", "hermes.cmd") or argv[1] != "-p":
+ if stdin_file or len(argv) < 3 or cli not in ("hermes", "hermes.exe") or argv[1] != "-p":
return contextlib.nullcontext()
from tools.bot_mode_probe import _hermes_root
from tools.bot_relay import acquire_turn_lock
@@ -531,7 +531,7 @@ def _wait_live_dm(home: str, delivery_id: str, *, dm_file: "str | os.PathLike |
def _local_delivery_home(argv: list[str]) -> Path | None:
cli = (argv[0] if argv else "").rsplit("\\", 1)[-1].rsplit("/", 1)[-1]
- if len(argv) < 3 or cli not in ("hermes", "hermes.exe", "hermes.cmd") or argv[1] != "-p":
+ if len(argv) < 3 or cli not in ("hermes", "hermes.exe") or argv[1] != "-p":
return None
from tools.bot_mode_probe import _hermes_root, _roster
diff --git a/tools/bot_relay.py b/tools/bot_relay.py
index bdc00a01443..6a761f3a2b0 100644
--- a/tools/bot_relay.py
+++ b/tools/bot_relay.py
@@ -507,13 +507,13 @@ def _hermes_cli() -> str:
selects current dependencies at child start. Keep the historical fallbacks
for external/developer installs that have no published launcher (#93590).
"""
- names = ("hermes.exe", "hermes.cmd") if sys.platform == "win32" else ("hermes",)
- launchers = Path(__file__).resolve().parents[1] / ".hermes" / "bin"
- for name in names:
- published = launchers / name
- if published.is_file():
- return str(published)
- sibling = Path(sys.executable or "").parent / names[0]
+ # Do not select batch shims: cmd.exe reinterprets otherwise literal argv
+ # (for example an ampersand in a query-file path), even with shell=False.
+ name = "hermes.exe" if sys.platform == "win32" else "hermes"
+ published = Path(__file__).resolve().parents[1] / ".hermes" / "bin" / name
+ if published.is_file():
+ return str(published)
+ sibling = Path(sys.executable or "").parent / name
return str(sibling) if sibling.is_file() else shutil.which("hermes") or "hermes"