Skip to content

fix: emit JSON when --level is warn/fail (#373) - #376

Closed
ranas-mukminov wants to merge 1 commit into
jtesta:masterfrom
ranas-mukminov:fix/373-json-level-always-print
Closed

ranas-mukminov wants to merge 1 commit into
jtesta:masterfrom
ranas-mukminov:fix/373-json-level-always-print

Conversation

@ranas-mukminov

Copy link
Copy Markdown

Summary

Fixes #373: combining --json/-j with --level=warn or --level=fail silently discards all JSON output (blank line only), even though the exit code remains correct.

Root cause

JSON is emitted via out.info(json.dumps(...)). OutputBuffer._print() drops messages below the configured minimum level unless always_print=True. With --level=warn, info-level JSON is filtered out.

Fix

Pass always_print=True on all three JSON emit sites in ssh_audit.py (standard audit, policy evaluation, and algorithm lookup). This matches the Option A behavior described in #373: --level continues to filter text output; JSON always gets a full document.

Test plan

  • Unit test: test_outputbuffer_always_print_bypasses_level (level=warn drops info; always_print=True keeps it)
  • PYTHONPATH=src pytest test/test_outputbuffer.py — 9 passed
  • Confirmed the three out.info(json.dumps(...)) call sites now include always_print=True

JSON is written through out.info(), which OutputBuffer drops when
--level is above info. Pass always_print=True on all JSON emit sites
so -j/--json still produces a parseable document.

Adds a unit test covering always_print bypassing the level filter.
@jtesta

jtesta commented Oct 17, 2026

Copy link
Copy Markdown
Owner

Closing as per rationale in: #373 (comment)

@jtesta jtesta closed this Oct 17, 2026
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.

Using --level=warn/--level=fail silently suppresses all JSON output

2 participants