Repository navigation
Add --json output for breeze ui check-translation-completeness (#75772) - #75809
Alwaysgaurav1 wants to merge 6 commits into
Conversation
…e#75772) - Add --json flag to breeze ui check-translation-completeness. - Output pure machine-readable JSON on stdout without Rich formatting or ANSI codes. - Suppress local reproduction CI banners when running with --json. - Redirect informational narration to stderr when composing with --add-missing and --remove-unused in JSON mode. - Add unit tests for build_completeness_report and command stdout purity under CI. - Update documentation and regenerated CLI help image and text assets.
aaiss0927
left a comment
There was a problem hiding this comment.
Hi @Alwaysgaurav1, thanks for picking this up — full disclosure: I'm the author of #75772 and, as noted there, I had an implementation in progress; it's now open in parallel as #75831 (per the project's parallel-work policy, maintainers will pick whichever implementation fits best).
Since the two PRs will be compared anyway, I encoded the acceptance criteria from #75772 as pytest probes and ran them against this branch. Three findings, repro tests at the bottom:
1. Fatal errors inside the computation leak onto stdout in --json mode. The quiet-flag approach routes the enumerated narration to stderr, but anything not enumerated still prints to stdout. Concretely: a locale without a PLURAL_SUFFIXES entry makes expand_plural_keys() print Error: No plural suffixes defined for language 'xy' via get_console() (stdout) and exit 1 — so breeze ui check-translation-completeness --json | jq gets ANSI error text on the data stream exactly when the consumer needs a clean failure.
2. Same for unreadable locale files. compare_keys() narrates Error loading <path>: ... via console_print (stdout), which ends up interleaved with the JSON document.
Both leaks would be closed at once by wrapping the whole computation in contextlib.redirect_stdout(...) the way breeze ci verify --json does (#73241) — that also future-proofs the stdout contract against any console print added to the compute path later, instead of having to keep the quiet-flag enumeration complete forever.
3. Default (table) mode output is not fully preserved. Moving the --language validation to the top of the command changes what table mode prints for an invalid/en language: upstream prints the locale-files table and the Summary of differences by language: header before exiting 2, while this branch prints only the error line. That contradicts the "Preserved byte-identical terminal table formatting and exit code semantics when --json is omitted" claim in the description (and the corresponding acceptance criterion in #75772). Hoisting the validation only under as_json keeps table mode untouched.
On the plus side: the complete verdict semantics check out — I specifically probed the post---add-missing state (nothing missing, only TODO stubs) and complete correctly stays false.
None of the three gaps is exercised by the PR's tests (the purity test covers the happy path only), so the probes below might be worth adopting as regression tests whichever implementation lands.
pytest repro — 3 probes that fail on this branch
import json
import re
import pytest
from click.testing import CliRunner
import airflow_breeze.commands.ui_commands as ui_commands
from airflow_breeze.commands.ui_commands import check_translation_completeness
ANSI = re.compile(r"\x1b\[[0-9;]*m")
@pytest.fixture
def locales(tmp_path, monkeypatch):
def make(spec):
for locale, files in spec.items():
d = tmp_path / locale
d.mkdir(exist_ok=True)
for fname, content in files.items():
(d / fname).write_text(content if isinstance(content, str) else json.dumps(content))
monkeypatch.setattr(ui_commands, "LOCALES_DIR", tmp_path)
return make
def test_stdout_stays_pure_when_computation_aborts(locales):
locales({"en": {"app.json": {"a": "A"}}, "xy": {"app.json": {"a": "X"}}})
result = CliRunner().invoke(check_translation_completeness, ["--json"])
assert result.exit_code != 0
# fails here: "Error: No plural suffixes defined for language 'xy'" lands on stdout
assert result.stdout.strip() == ""
def test_malformed_locale_file_does_not_leak_to_stdout(locales):
locales({"en": {"app.json": {"a": "A"}}, "de": {"app.json": "{not valid json"}})
result = CliRunner().invoke(check_translation_completeness, ["--json"])
# fails here: "Error loading <path>: ..." is interleaved with stdout
assert "Error loading" not in ANSI.sub("", result.stdout)
def test_default_table_error_path_unchanged(locales):
locales({"en": {"app.json": {"a": "A"}}, "de": {"app.json": {"a": "D"}}})
result = CliRunner().invoke(check_translation_completeness, ["--language", "zz"])
assert result.exit_code == 2
# fails here: upstream prints the tables before exiting 2; this branch prints only the error
assert "Summary of differences by language:" in ANSI.sub("", result.output)|
Hi @aaiss0927, Thank you for the thorough review and for providing the reproducible test probes! I have pushed an update addressing all three points:
|
|
Thanks @Alwaysgaurav1 — that was quick. I re-ran the acceptance probes from my review against 13699b9 and all three pass now; the One observation for the record, since the two PRs will be compared: the fix goes beyond the With behavior now effectively equivalent, the substantive remaining difference is the output schema. The |
|
Thanks for working on this, @Alwaysgaurav1. #75831 implements the same Drafted-by: Claude Code (Claude Opus 5); reviewed by @potiuk before posting |
closes: #75772
Description
Adds a
--jsonflag tobreeze ui check-translation-completenessthat outputs a machine-readable JSON document onstdoutwithout Rich ANSI styling or narration:build_completeness_report()returning{ "languages": { ... }, "complete": bool }.--jsonis omitted.stdoutwhen running with--jsonusingSKIP_LOCAL_REPRODUCTION.stderrwhen composing--jsonwith--add-missingand--remove-unused.output_ui_check-translation-completeness.svgand.txt).--add-missing/--remove-unused.Was generative AI tooling used to co-author this PR?