Skip to content

The agent that grows with you

test(gateway): mirror Windows subprocess decoding; cover the UTF-16 BOM path

Teknium90b6520bb305
diff --git a/tests/hermes_cli/test_gateway_runtime_service.py b/tests/hermes_cli/test_gateway_runtime_service.py
index 55308dabcee..5dfc78682c9 100644
--- a/tests/hermes_cli/test_gateway_runtime_service.py
+++ b/tests/hermes_cli/test_gateway_runtime_service.py
@@ -379,9 +379,16 @@ def test_task_discovery_reads_localized_schtasks_output(tmp_path, monkeypatch):
# The console code page this host would report; the bytes below are what such a console writes.
monkeypatch.setattr(gateway_windows, "_windows_console_encodings", lambda: ["cp936"])
- def run(argv, *_args, encoding=None, **_kwargs): # subprocess semantics: bytes, or decoded with encoding
+ def run(argv, *_args, encoding=None, **_kwargs):
+ # Windows subprocess decodes text in a reader thread: a decode error there leaves stdout None
+ # (main then read an empty task list and fell through to an unmanaged spawn), it does not raise.
data = next(text for key, text in out.items() if key in argv).encode("cp936")
- return SimpleNamespace(returncode=0, stdout=data.decode(encoding) if encoding else data)
+ if encoding:
+ try:
+ data = data.decode(encoding)
+ except UnicodeDecodeError:
+ data = None
+ return SimpleNamespace(returncode=0, stdout=data)
monkeypatch.setattr(service, "_run", run)
found = service.discover_existing_gateway_service(home, deadline=time.monotonic() + 5)
diff --git a/tests/hermes_cli/test_gateway_windows.py b/tests/hermes_cli/test_gateway_windows.py
index 17fffac45b2..7db666ffe9f 100644
--- a/tests/hermes_cli/test_gateway_windows.py
+++ b/tests/hermes_cli/test_gateway_windows.py
@@ -860,3 +860,11 @@ def test_wizard_install_service_asks_once_and_never_starts_after_windows_install
assert installs == [{"force": False, "start_now": True, "start_on_login": True}]
assert starts == []
+
+
+def test_decode_schtasks_output_honours_a_utf16_bom():
+ """A genuine UTF-16 write (BOM) decodes as UTF-16, never as a code page; a malformed one falls
+ back like any other bytes instead of raising past callers that catch only timeout/OS errors."""
+ text = "Herm\u00e9s"
+ assert gateway_windows._decode_schtasks_output(text.encode("utf-16")) == text
+ assert gateway_windows._decode_schtasks_output(b"\xff\xfe<\x00?")