From 8aab80221dea80968abc6191b584f9e7888ab282 Mon Sep 17 00:00:00 2001 From: Joel Podolsky <215428744+fllsales@users.noreply.github.com> Date: Sat, 31 Oct 2026 03:30:22 -0400 Subject: [PATCH] fix(openclaw-persona-forge): print gacha output as UTF-8 on non-UTF-8 stdout On Windows, piped stdout defaults to cp1252, so `python3 gacha.py` crashed on its first banner line with UnicodeEncodeError. That covers agent shell tools and gacha.sh. Reconfigure stdout to UTF-8 before main(), the same approach instinct-cli.py took for #1855. The existing tests set PYTHONUTF8=1, which hid the crash. The new case forces PYTHONIOENCODING=cp1252 without PYTHONUTF8, so it reproduces on any OS: it fails on the previous gacha.py and passes with this change. Co-Authored-By: Claude Opus 5.5 --- skills/openclaw-persona-forge/gacha.py | 3 +++ tests/scripts/openclaw-persona-forge-gacha.test.js | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/skills/openclaw-persona-forge/gacha.py b/skills/openclaw-persona-forge/gacha.py index a850c8c73..94843180c 100755 --- a/skills/openclaw-persona-forge/gacha.py +++ b/skills/openclaw-persona-forge/gacha.py @@ -221,4 +221,7 @@ def main(): if __name__ == "__main__": + # Windows 管道输出默认 cp1252,打印中文和框线字符会抛 UnicodeEncodeError + if hasattr(sys.stdout, "reconfigure"): + sys.stdout.reconfigure(encoding="utf-8") main() diff --git a/tests/scripts/openclaw-persona-forge-gacha.test.js b/tests/scripts/openclaw-persona-forge-gacha.test.js index 6f5cceb8d..db3741628 100644 --- a/tests/scripts/openclaw-persona-forge-gacha.test.js +++ b/tests/scripts/openclaw-persona-forge-gacha.test.js @@ -26,11 +26,11 @@ function findPython() { return null; } -function runGacha(pythonBin, arg) { +function runGacha(pythonBin, arg, env = { ...process.env, PYTHONUTF8: '1' }) { return spawnSync(pythonBin, [SCRIPT, arg], { encoding: 'utf8', maxBuffer: 10 * 1024 * 1024, - env: { ...process.env, PYTHONUTF8: '1' }, + env, }); } @@ -71,6 +71,11 @@ function main() { ['clamps negative draws to one', () => { assertSingleDrawOutput(runGacha(pythonBin, '-3')); }], + ['prints when piped stdout is not UTF-8 (Windows cp1252 default)', () => { + const env = { ...process.env, PYTHONIOENCODING: 'cp1252' }; + delete env.PYTHONUTF8; + assertSingleDrawOutput(runGacha(pythonBin, '1', env)); + }], ]; for (const [name, fn] of tests) {