mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-17 05:22:17 +00:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
b38be6a7f6
commit
8aab80221d
2 files changed
+10
-2
No files matched your search
@@ -221,4 +221,7 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Windows 管道输出默认 cp1252,打印中文和框线字符会抛 UnicodeEncodeError
|
||||
if hasattr(sys.stdout, "reconfigure"):
|
||||
sys.stdout.reconfigure(encoding="utf-8")
|
||||
main()
|
||||
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user