Skip to content

The agent that grows with you

fix(cron): make the Windows bot-chat witness a real windows_only nested parent

liuhao1024151b07010785
diff --git a/tests/cron/test_cron_bot_chat_delivery.py b/tests/cron/test_cron_bot_chat_delivery.py
index 0b663bbbc06..b432ecea0e3 100644
--- a/tests/cron/test_cron_bot_chat_delivery.py
+++ b/tests/cron/test_cron_bot_chat_delivery.py
@@ -6,6 +6,7 @@ preflight exemption, create-time validation, the subprocess delivery lane,
and the delivery-targets listing used by UI pickers.
"""
+import json
import os
import subprocess
import sys
@@ -311,24 +312,44 @@ def test_bot_chat_turn_failure_tail_decodes_lossily(tmp_path):
assert result.stderr == "boom before \ufffd after\n"
- getattr(sys.flags, "utf8_mode", 0),
- reason="parent already in UTF-8 mode; the ANSI-codepage mismatch is not exercisable",
-)
def test_bot_chat_turn_roundtrips_accented_utf8_reply(tmp_path):
"""The delivery child writes UTF-8 unconditionally — hermes_cli reconfigures its
own streams via hermes_bootstrap on Windows even under PYTHONIOENCODING=cp1252 —
while the gateway parent there is NOT started in UTF-8 mode, so text=True alone
decoded the pipes with the ANSI code page: the reply came back mojibake'd, or the
reader thread died on bytes undefined in cp1252 and the reply was silently lost
- while the delivery still booked as delivered (#115894)."""
+ while the delivery still booked as delivered (#115894).
+
+ The gateway parent is a nested interpreter explicitly NOT in UTF-8 mode
+ (``PYTHONUTF8=0`` / ``-X utf8=0``), so its Popen(text=True) decodes with the
+ ANSI code page exactly like the production parent; the stand-in child writes
+ raw UTF-8 bytes through sys.stdout.buffer the way the bootstrapped hermes_cli
+ child does, independent of any locale. On the pre-fix branch the decode dies
+ on 0x8D (second byte of UTF-8 "Í", undefined in cp1252) inside the drain
+ thread and stdout comes back empty — RED; with the win32 UTF-8 pin the text
+ round-trips byte-for-byte. The JSON verdict rides the nested stdout with
+ ensure_ascii escapes, so the outer pipe encoding cannot distort it."""
text = "AÇÃO ÍNDICE: relatório nº 3\n"
- child = "import sys; sys.stdout.write({!r})".format(text)
- result = sched_delivery._run_bot_chat_turn(
- [sys.executable, "-c", child], _child_env(), str(tmp_path / "turn.json"), timeout=15)
-
- assert result.returncode == 0
- assert result.stdout == text
+ nested = textwrap.dedent("""
+ import json, os, sys
+ from cron.scheduler_delivery import _run_bot_chat_turn
+ child = "import sys; sys.stdout.buffer.write({!r})".format(sys.argv[1].encode("utf-8"))
+ result = _run_bot_chat_turn(
+ [sys.executable, "-c", child], dict(os.environ), sys.argv[2], timeout=30)
+ print(json.dumps(
+ {"returncode": result.returncode, "stdout": result.stdout, "stderr": result.stderr}))
+ """)
+ env = {**_child_env(), "PYTHONUTF8": "0"}
+ env.pop("PYTHONIOENCODING", None)
+ res = subprocess.run(
+ [sys.executable, "-X", "utf8=0", "-c", nested, text, str(tmp_path / "turn.json")],
+ env=env, timeout=60, check=True, capture_output=True, encoding="utf-8")
+
+ result = json.loads(res.stdout)
+ assert result["returncode"] == 0
+ assert result["stdout"] == text
+ assert result["stderr"] == ""
# ── delivery-targets listing (UI pickers) ────────────────────────────────────