Skip to content

The agent that grows with you

fix(gateway): read auth.json as UTF-8 in _read_nous_provider_state

Nolan2e227d74f4ee
diff --git a/tests/hermes_cli/test_auth_store_windows_encoding.py b/tests/hermes_cli/test_auth_store_windows_encoding.py
index 468189b27e0..3082863e9ae 100644
--- a/tests/hermes_cli/test_auth_store_windows_encoding.py
+++ b/tests/hermes_cli/test_auth_store_windows_encoding.py
@@ -319,3 +319,33 @@ class TestAuthJsonSiblingReaders:
assert main_mod._has_any_provider_configured() is True
+ def test_managed_tool_gateway_reads_non_ascii_nous_state(
+ self, hermes_home, windows_default_encoding
+ ):
+ """tools.managed_tool_gateway._read_nous_provider_state reads auth.json.
+
+ The Nous provider entry can carry a non-ASCII label. Under the
+ Windows-default-encoding fixture a no-encoding read raises and the
+ broad except swallows it, returning None — so the gateway treats
+ Nous as unconfigured.
+ """
+ store = {
+ "version": auth.AUTH_STORE_VERSION,
+ "providers": {
+ "nous": {
+ "agent_key": "k",
+ # Non-ASCII label → UTF-8 bytes cp1252 cannot decode.
+ "label": "工作账号",
+ }
+ },
+ }
+ _write_utf8(hermes_home / "auth.json", store)
+
+ from tools.managed_tool_gateway import _read_nous_provider_state
+
+ nous = _read_nous_provider_state()
+ assert nous is not None
+ assert nous.get("agent_key") == "k"
+ # The non-ASCII label round-trips intact.
+ assert nous.get("label") == "工作账号"
+
diff --git a/tools/managed_tool_gateway.py b/tools/managed_tool_gateway.py
index c46a48975bb..0ec3b524608 100644
--- a/tools/managed_tool_gateway.py
+++ b/tools/managed_tool_gateway.py
@@ -38,7 +38,7 @@ def _read_nous_provider_state() -> Optional[dict]:
path = auth_json_path()
if not path.is_file():
return None
- data = json.loads(path.read_text(encoding="utf-8"))
+ data = json.loads(path.read_text(encoding="utf-8-sig"))
providers = data.get("providers", {})
if not isinstance(providers, dict):
return None