Skip to content

fix(audit): force UTF-8 stdout in report.py so it renders on a cp1251 console#105

Merged
PhysShell merged 1 commit into
mainfrom
claude/audit-cp1251-utf8
Jun 28, 2026
Merged

fix(audit): force UTF-8 stdout in report.py so it renders on a cp1251 console#105
PhysShell merged 1 commit into
mainfrom
claude/audit-cp1251-utf8

Conversation

@PhysShell

@PhysShell PhysShell commented Jun 25, 2026

Copy link
Copy Markdown
Owner

What

report.py main() prints the rendered markdown/HTML health report, which contains , ·, . On a Windows console using a locale codepage — cp1251 on a Russian-locale box, which is the STS desktop target's own build/run environment — that print() raises UnicodeEncodeError and the report is lost:

File ".../report.py", line 317, in main
    print(render_markdown(meta, cov, scored))
UnicodeEncodeError: 'charmap' codec can't encode character '≥' ... maps to <undefined>

Fix

Force sys.stdout to UTF-8 in main() before rendering. normalize/score/run_static already print only ASCII json.dumps or write files with encoding="utf-8", so report.py was the lone crash site.

Test

Adds a regression selftest that renders markdown + html to a simulated cp1251 stdout and asserts main() does not crash (report selftest: 34 → 36 checks). Verified on a real cp1251 box: report.py --format markdown (no PYTHONUTF8) now exits 0 and renders the em-dash/ cleanly — the exact invocation that crashed before.

How it was found

Surfaced running audit/ end-to-end on the real STS codebase (STS_new/SectorTS, net472 / WPF / DevExpress): OwnSharp → SARIF → audit/aggregate produced a correct 380-finding health report, but the markdown render died on the cp1251 console until PYTHONUTF8=1 was forced. This removes the need for that workaround.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved report rendering on Windows consoles so markdown and HTML outputs no longer fail with encoding errors when special characters are present.
  • Tests

    • Added regression coverage to verify report generation succeeds under a cp1251-style console environment.

… console

report.py main() prints the rendered markdown/HTML, which carries the glyphs '>=', '·', '—'. On a Windows console using a locale codepage (cp1251 on a Russian-locale box - the STS desktop target's own environment) that print() raises UnicodeEncodeError and the report is lost. Force sys.stdout to UTF-8 before rendering. normalize/score/run_static already print only ASCII json.dumps or write files with encoding=utf-8, so report.py was the lone crash site.

Adds a selftest that renders markdown + html to a simulated cp1251 stdout and asserts no crash (report selftest: 34 -> 36 checks).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 15857b14-544c-4236-97bc-57b52f45feda

📥 Commits

Reviewing files that changed from the base of the PR and between 23d34ec and 74d1fb7.

📒 Files selected for processing (1)
  • audit/aggregate/report.py

📝 Walkthrough

Walkthrough

The report CLI now reconfigures standard output to UTF-8 when supported and adds a self-test that renders markdown and HTML under a simulated cp1251 console to verify non-ASCII glyphs do not fail output.

Changes

Report output encoding

Layer / File(s) Summary
UTF-8 stdout setup
audit/aggregate/report.py
main() conditionally reconfigures sys.stdout to UTF-8 before report rendering.
cp1251 regression selftest
audit/aggregate/report.py
_selftest() creates temporary findings JSON, swaps in a cp1251 stdout wrapper, and verifies markdown and HTML rendering return 0 without UnicodeEncodeError.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • PhysShell/Own.NET#101: Adds the markdown and HTML report rendering flow that this PR’s encoding regression test exercises.

Poem

A bunny hopped by with a code-savvy grin,
“UTF-8, little glyphs, come on in!”
Markdown and HTML now leap through the haze,
While cp1251 loses its grumpy old ways.
🐰✨

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: forcing UTF-8 stdout in report.py to avoid cp1251 console encoding errors.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/audit-cp1251-utf8

Comment @coderabbitai help to get the list of available commands.

@PhysShell
PhysShell merged commit 81876b2 into main Jun 28, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant