CodeAlex 0e9690493d
fix(scripts): keep sync_labels.py from crashing on non-UTF-8 stdio (#7473)
* fix(scripts): keep sync_labels.py from crashing on non-UTF-8 stdio

The ✓ / ✗ status glyphs and the em dash in the Done line crashed the sync
with UnicodeEncodeError whenever stdout was redirected on a host whose
stdio encoding cannot represent them (Windows code pages, POSIX C locale,
PYTHONIOENCODING=ascii) — after `gh label create --force` had already run,
leaving a half-applied sync and a traceback. gh's UTF-8 diagnostics were
additionally decoded with the host locale, mangling failure messages.
Closes #7389.

- Reconfigure stdout/stderr in main(): UTF-8 with backslashreplace when
  redirected, backslashreplace only on consoles.
- Decode the gh subprocess as UTF-8 with errors="replace", matching
  scripts/support_bundle.py's _run_command.
- Add backend/tests/test_sync_labels_script.py: hermetic offline cases
  (stub yaml, stub gh) running the real script under PYTHONIOENCODING=ascii
  for the success path, a UTF-8 gh failure, and --dry-run. All three go
  red on the unfixed script.

* style(tests): fix sync-labels regression lint

* docs(scripts): document label sync encoding policy

---------

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-10-25 15:30:07 +08:00
..