From 7b8a4d74f9352bd592b5a80c945b5a947d4ef957 Mon Sep 17 00:00:00 2001 From: Rod Boev Date: Mon, 13 Jul 2026 21:29:59 -0400 Subject: [PATCH] fix(gateway): cover discord update-response utf-8 path (#37423) --- plugins/platforms/discord/adapter.py | 2 +- tests/gateway/test_gateway_utf8_encoding.py | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/plugins/platforms/discord/adapter.py b/plugins/platforms/discord/adapter.py index 161669a8a6e..6e66a2c269a 100644 --- a/plugins/platforms/discord/adapter.py +++ b/plugins/platforms/discord/adapter.py @@ -8164,7 +8164,7 @@ def _define_discord_view_classes() -> None: home = get_hermes_home() response_path = home / ".update_response" tmp = response_path.with_suffix(".tmp") - tmp.write_text(answer) + tmp.write_text(answer, encoding="utf-8") tmp.replace(response_path) logger.info( "Discord update prompt answered '%s' by %s", diff --git a/tests/gateway/test_gateway_utf8_encoding.py b/tests/gateway/test_gateway_utf8_encoding.py index 691311888de..c900d09d931 100644 --- a/tests/gateway/test_gateway_utf8_encoding.py +++ b/tests/gateway/test_gateway_utf8_encoding.py @@ -1,6 +1,7 @@ -"""Static guard: every ``read_text`` / ``write_text`` call under ``gateway/`` -must pass an explicit ``encoding=`` keyword argument so non-UTF-8 Windows -locales don't corrupt file IPC. Mirrors the AST-based guard pattern in +"""Static guard: every ``read_text`` / ``write_text`` call in the gateway and +bundled update-response adapters must pass an explicit ``encoding=`` keyword +argument so non-UTF-8 Windows locales don't corrupt file IPC. Mirrors the +AST-based guard pattern in ``tests/tools/test_windows_compat.py``. """ @@ -8,14 +9,21 @@ import ast import pathlib import pytest -GATEWAY_DIR = pathlib.Path(__file__).resolve().parents[2] / "gateway" +REPO_ROOT = pathlib.Path(__file__).resolve().parents[2] +GATEWAY_DIR = REPO_ROOT / "gateway" +UPDATE_RESPONSE_FILES = ( + REPO_ROOT / "plugins/platforms/discord/adapter.py", + REPO_ROOT / "plugins/platforms/telegram/adapter.py", + REPO_ROOT / "plugins/platforms/feishu/adapter.py", +) METHODS = {"read_text", "write_text"} SUPPRESSION = "# gateway-utf8: ok" def _find_violations(): violations = [] - for py_file in sorted(GATEWAY_DIR.rglob("*.py")): + py_files = list(GATEWAY_DIR.rglob("*.py")) + list(UPDATE_RESPONSE_FILES) + for py_file in sorted(py_files): source = py_file.read_text(encoding="utf-8") source_lines = source.splitlines() try: @@ -35,7 +43,7 @@ def _find_violations(): lineno = node.lineno if lineno <= len(source_lines) and SUPPRESSION in source_lines[lineno - 1]: continue - rel = py_file.relative_to(GATEWAY_DIR.parent) + rel = py_file.relative_to(REPO_ROOT) violations.append(f"{rel}:{lineno}") return violations