Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions audit/aggregate/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ def main(argv: list[str] | None = None) -> int:
resource=d.get("resource")) for d in payload.get("findings", [])]
scored = score(findings, tax, args.line_tol)
meta = {"target": args.target, "commit": args.commit, "line_tol": args.line_tol}
# Windows consoles default to the locale codepage (cp1251 on a Russian-locale box —
# the STS target environment); the rendered report carries '≥', '·', '—'. Force UTF-8
# so a raw markdown/HTML print() does not UnicodeEncodeError on a non-UTF-8 console.
if hasattr(sys.stdout, "reconfigure"):
sys.stdout.reconfigure(encoding="utf-8")
if args.format == "json":
print(json.dumps(render_json(meta, cov, scored), indent=2))
elif args.format == "sarif":
Expand Down Expand Up @@ -407,6 +412,29 @@ def check(ok: bool, msg: str) -> None: # total derives from the call count
check("third-party: DevExpress." in h, "html coverage must report the suppressed finding")
check("analysis-skipped" in h, "html coverage must surface analysis-skipped notes")

# cp1251-console regression: the renderers emit non-cp1251 glyphs ('≥','·','—'), so on
# a Russian-locale Windows console (the STS target env) a raw print() in main() would
# UnicodeEncodeError. main() forces utf-8 stdout — verify it renders markdown/html to a
# simulated cp1251 stdout without crashing (the bug fixed alongside this test).
import io
import tempfile
fdicts = [{"tool": f.tool, "path": f.path, "line": f.line, "rule": f.rule,
"message": f.message, "category": f.category,
"category_name": f.category_name, "resource": f.resource}
for f in findings if f.scored]
with tempfile.TemporaryDirectory() as td:
fpath = Path(td) / "findings.json"
fpath.write_text(json.dumps({"coverage": cov, "findings": fdicts}), encoding="utf-8")
for fmt in ("markdown", "html"):
saved, sys.stdout = sys.stdout, io.TextIOWrapper(io.BytesIO(), encoding="cp1251")
try:
rc = main(["--findings", str(fpath), "--format", fmt])
except UnicodeEncodeError:
rc = -1
finally:
sys.stdout = saved
check(rc == 0, f"main(--format {fmt}) must render to a cp1251 stdout without crashing")

fails = [c for c in checks if c]
for f in fails:
print(f"REPORT SELFTEST FAIL: {f}")
Expand Down
Loading