mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +00:00
fix(gateway): cover discord update-response utf-8 path (#37423)
This commit is contained in:
parent
09910bc3a5
commit
7b8a4d74f9
2 changed files with 15 additions and 7 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue