Skip to content

The agent that grows with you

test(gateway): prove WSH decodes the UTF-16 Startup chainer on Windows

unsupportedpastelsf29f0d92b92f
diff --git a/tests/hermes_cli/test_gateway_windows_wsh_live.py b/tests/hermes_cli/test_gateway_windows_wsh_live.py
new file mode 100644
index 00000000000..bd24f714424
--- /dev/null
+++ b/tests/hermes_cli/test_gateway_windows_wsh_live.py
@@ -0,0 +1,35 @@
+"""Live Windows probe: Windows Script Host decodes the UTF-16 Startup chainer, so a target under a
+non-ASCII directory is found and launched (W13, #143547).
+
+Runs only on real Windows. It writes the chainer through the production ``_install_startup_entry``
+under a temp APPDATA and runs it with ``cscript.exe``. No task or real Startup entry is touched.
+"""
+
+import subprocess
+import time
+
+import pytest
+
+from hermes_cli import gateway_windows
+
+
+def test_startup_chainer_launches_a_target_under_a_non_ascii_directory(tmp_path, monkeypatch):
+ monkeypatch.setenv("APPDATA", str(tmp_path / "AppData" / "Roaming"))
+ service_dir = tmp_path / "方舟 Usuário" / "gateway-service"
+ service_dir.mkdir(parents=True)
+ marker = service_dir / "ran.txt"
+ script_path = service_dir / "gateway.cmd"
+ target = f"CreateObject(\"Scripting.FileSystemObject\").CreateTextFile({gateway_windows._quote_vbs_string(str(marker))}).Close\r\n"
+ script_path.with_suffix(".vbs").write_text(target, encoding="utf-16", newline="")
+
+ entry = gateway_windows._install_startup_entry(script_path)
+ run = subprocess.run(["cscript.exe", "//nologo", str(entry)], capture_output=True, text=True, timeout=60, check=False)
+ assert run.returncode == 0, run.stdout + run.stderr
+
+ # The chainer quits silently when FileExists(target) is false, so only a correctly decoded path
+ # reaches the target; it is started asynchronously, hence the poll.
+ deadline = time.monotonic() + 30
+ while not marker.exists() and time.monotonic() < deadline:
+ time.sleep(0.2)
+ assert marker.exists(), "the Startup chainer did not reach the target under the non-ASCII directory"