Repository navigation
Fix CLI output on legacy Windows code pages - #449
Conversation
Signed-off-by: Efe Gökdemir <[email protected]>
chrisknvidia
left a comment
There was a problem hiding this comment.
Thanks for picking this up, and for the clear test. This is the one-line approach from #446 and it looks right to me: reconfigure keeps the same stdout object, so the module-level Rich consoles keep working, stderr already uses backslashreplace in Python so it doesn't need the same treatment, and your test fails without the change.
Two mechanical things before it can merge: CHANGELOG.md now conflicts with main (please rebase and keep both bullets under Unreleased > Fixed), and CI hasn't run yet because first-time fork workflows need a maintainer to approve them. It will need to be green after the rebase.
A few things for the maintainers to weigh, none of them blocking from my side: errors="replace" also affects commands that print JSON to stdout (tier3 migrate-dataset preview and tier3 validate --json), so on a legacy code page non-encodable characters become ? silently instead of failing; using ensure_ascii=True in those two spots would avoid that. The reconfigure runs in the group callback, so root --help/--version are parsed before it. And the test could be parametrized over cp437 and cp1252 as well as cp936 (U+2022 is encodable in cp1252, so that variant needs another glyph).
Integrate upstream 7ae25d2 while preserving its history as the second merge parent. Resolve the changelog conflict without dropping upstream release notes. Configure stdout before Click parses eager options, including root --help. Use ASCII JSON escapes for machine-readable dataset previews and validation output so decoded Unicode values survive legacy terminal encodings. Expand regression coverage for cp936, cp1252, ASCII, and UTF-8. Validation on unchanged candidate tree 5621825: - Original focused tests: 67 passed; lint and wheel/sdist build passed. - Expanded encoding/migration/banner/dataset tests: 93 passed. - Static/mocked selection: 697 passed, 2 skipped. - Audited reporting/model/embedding selection: 2447 passed, 7 skipped, 2 failed. Untouched upstream, excluding the denied socket test: 2447 passed, 7 skipped, 1 identical golden failure. - Click 8.5.1 implicit flag defaults differ from the golden on unchanged upstream. AF_UNIX creation was denied before repository code; its test and implementation match upstream. Neither issue was changed. - An earlier scanner-install-related CLI failure also reproduces upstream. Denied installer and socket operations were not retried. - The original 27483-test full run stopped around 17 percent. Its 17 anonymous failure markers cannot be individually identified from retained logs. Guarded diagnostic runs produced harness artifacts and do not count as a passing product suite. - Counts overlap and must not be summed. Windows was not available; code page tests use Linux text streams and subprocess encodings. No complete full-suite pass or upstream merge readiness is claimed. This updates the existing PR for review and CI with those limitations. Signed-off-by: Efe Gökdemir <[email protected]>
chrisknvidia
left a comment
There was a problem hiding this comment.
Re-reviewed at f26c087. All three points from my last review are fixed:
- Root
--help/--version:_EncodingSafeGroup.parse_argsreconfigures stdout before Click handles eager options, andtest_root_help_before_callback_supports_code_pagescovers it in a subprocess withPYTHONIOENCODING=<cp>:strict. - JSON output:
migrate-datasetandtier3 validate --jsonnow useensure_ascii=True, so they round-trip non-ASCII values exactly instead of turning them into?. - Coverage: cp936, cp1252, ascii and utf-8.
Checked locally: tests/test_cli_stdout_encoding.py passes (17). All 17 fail when I put the base src/ back, so the tests catch the bug. The -k cli subset passes (1726), and ruff check / ruff format --check are clean.
One optional follow-up, not blocking: tier3 import-traces still prints each skipped item with json.dumps(item, ensure_ascii=False) (cli.py, around line 343). On a legacy code page that line now degrades to ? instead of crashing, which is fine for a summary, but ensure_ascii=True there would keep it exact like the other JSON output.
The branch is behind main but has no conflicts. LGTM.
27edd9c to
6f01536
Compare
Signed-off-by: Christopher Kevin <[email protected]>
chrisknvidia
left a comment
There was a problem hiding this comment.
Approving. All three earlier points are fixed, and I merged main into the branch (no conflicts; the encoding and image-build tests still pass).
rng1995
left a comment
There was a problem hiding this comment.
Automated review: 2 findings (0 P1, 0 P2, 2 P3); 2 posted inline.
Checked the stdout reconfigure in _EncodingSafeGroup, the two ensure_ascii=True JSON outputs, and the new tests, on this branch and on main, with legacy code pages simulated through PYTHONIOENCODING=cp936:strict / cp1252:strict and LC_ALL=zh_CN.GBK.
Under cp936, tier1 skills/skillevaluator --no-llm, --help, --version, tier3 validate --json and tier3 migrate-dataset all complete on this branch; on main, tier1 crashes in _print_summary_stats with the UnicodeEncodeError from #446.
Tests: tests/test_cli_stdout_encoding.py 17 passed (16 of them fail against main's src/); with test_cli_banner, test_commands, tier3/test_dataset_migration, tier3/test_dataset_coverage and test_harbor_case_id_safety, 303 passed; golden/test_cli_surface plus the new file 20 passed; existing validate --json consumers (test_harbor_case_id_safety, validators/test_private_claude_parity) 55 passed.
The branch is 5 commits behind main (487910e) and conflicts with it in CHANGELOG.md only: both sides add a bullet at the top of Unreleased > Fixed, so keep both bullets when you merge main.
Merge upstream b38b71b without rewriting existing PR or maintainer history. Preserve both sides of the changelog. Keep migration previews and validation JSON readable when the actual output encoding can represent the data, and use ASCII escapes otherwise. Normalize only the test's CRLF comparison, extend encoding regressions, and include the encoding test file in the Windows CI job. Validation on the unchanged candidate tree: - 32 focused encoding tests passed; source/test Ruff lint passed. - Wheel and sdist build passed. - Related tests: 281 passed, 2 skipped, 44 failed. - All 44 failing test identities and provenance-key-location errors also reproduce on the unmodified PR head. The temporary fixture root is recognized as a repository in this environment. The security guard was not weakened or bypassed. - Native Windows was not available; CRLF was simulated on Linux. - Full make test was not run; previously denied socket operations were not retried. No complete full-suite or new hosted-CI pass is claimed. Signed-off-by: Efe Gökdemir <[email protected]>
Signed-off-by: Christopher Kevin <[email protected]>
chrisknvidia
left a comment
There was a problem hiding this comment.
Re-approving at the current head. f5e48d3 fixes both of Narendran's P3s: JSON stays readable when the stream encoding can represent it, and the stdout test is newline-agnostic. I merged main again; the only conflict was CHANGELOG.md, and I kept both entries. The encoding and CLI tests pass (144), and ruff is clean.
Signed-off-by: Christopher Kevin <[email protected]>
chrisknvidia
left a comment
There was a problem hiding this comment.
Re-approving after merging main again (no conflicts). The encoding tests still pass.
rng1995
left a comment
There was a problem hiding this comment.
Thank you @efegokdemir for your contribution and for your patience throughout the review process. The review findings are addressed: eager help configures stdout before rendering, JSON preserves Unicode values while remaining readable on capable encodings, and newline/code-page coverage includes Windows CI. Verified 32 encoding tests with exit 0 and changed-file Ruff checks. All inline threads are resolved and the PR merges cleanly with main. Approved; auto-merge remains subject to the required CI checks.
Summary
Fixes #446. Configure the CLI's stdout to replace characters its active encoding cannot represent. Rich summaries now complete on legacy Windows code pages instead of raising
UnicodeEncodeError.Verification
uv run ruff check .) passedRelease Impact
CHANGELOG.md