Files
hermes-agent/tests/tools/test_subprocess_utf8_encoding.py
teknium1 4ebda1dddb test: restore tools regression guards dropped by #120071
- test_code_kernel::TestModelFacingReset: reset stays in the schema under a stale
  kernel_mode and a model-shaped reset call really discards kernel state (#96787).
- test_computer_use::TestStartupTimeoutPhaseDetail: cua-driver ready timeout names
  the wedged phase + doctor hint, and the session stays un-started (#57025/#69372).
- test_file_operations::TestEscapeNativeToolArg (windows_only, was FAKE_OS): rg
  search and the node --check linter get native C:/ paths, not /c/ (#84303).
- test_file_tools::TestSSHConfigWriteGate (2): a ~/.ssh/config write goes through
  the real approval gate, BLOCKED with nobody present / in -q mode, nothing written (#93201).
- test_lazy_deps: a newer compatible plugin SDK is satisfied, never re-pinned down
  (#98407, #86992); windows_only real Matrix probe reports unsupported.
- test_mcp_empty_error_message: empty/whitespace exception messages still yield a
  diagnostic (#19417).
- test_mcp_stdio_children_dead: the fast-fail probe never calls the watcher on the
  plain path, no un-awaited coroutine (#96044).
- test_subprocess_utf8_encoding: real _op_whoami survives invalid UTF-8 child output (#53428/#55339).
- test_tts_output_timestamp: same-second TTS calls get distinct output files (#43911).
- test_windows_agent_loop_papercuts::TestAutocompleteDevicePaths: a relpath
  ValueError on a device path is skipped, not raised (#42016).
- test_windows_native_support::TestCronSchedulerBashResolution (2): cron .sh uses
  bash from PATH; missing bash is an actionable error, not WinError 2.
2026-09-23 10:34:54 -07:00

36 lines
1.4 KiB
Python

"""Regression test for #53428 (fix PR #55339): ``subprocess.run(text=True)``
decoding of secret-manager CLI output must never crash on undecodable bytes.
On Chinese Windows (cp936/GBK) ``text=True`` without ``encoding=`` decodes with
the locale codepage and crashes on non-GBK bytes (#47939, #53428, #57238);
``encoding='utf-8'`` alone still raises on non-UTF-8 bytes emitted by
Windows-native CLIs. ``scripts/check-windows-footguns.py`` enforces the
``encoding=`` half repo-wide; this drives the real ``_op_whoami`` against a
child that emits invalid UTF-8 so the ``errors='replace'`` half is exercised
on every host.
"""
from __future__ import annotations
import sys
from pathlib import Path
def test_op_whoami_survives_non_utf8_cli_output(tmp_path, monkeypatch):
from hermes_cli import onepassword_secrets_cli as op_cli
# _op_whoami runs ``[binary, "whoami"]``. Using the interpreter as the
# binary makes that ``python whoami``, i.e. run ./whoami from the cwd:
# a portable stand-in for an ``op`` that prints a non-UTF-8 account name.
(tmp_path / "whoami").write_text(
"import sys\n"
"sys.stdout.buffer.write(b'\\xff\\xfe caf\\xc3\\xa9@example.com\\n')\n",
encoding="utf-8",
)
monkeypatch.chdir(tmp_path)
identity = op_cli._op_whoami(Path(sys.executable), account="")
assert identity is not None
assert "café@example.com" in identity