Skip to content

Add --json output for breeze ui check-translation-completeness (#75772) - #75809

Open
Alwaysgaurav1 wants to merge 6 commits into
apache:mainfrom
Alwaysgaurav1:feat/75772-breeze-check-translation-completeness-json
Open

Alwaysgaurav1 wants to merge 6 commits into
apache:mainfrom
Alwaysgaurav1:feat/75772-breeze-check-translation-completeness-json

Conversation

@Alwaysgaurav1

Copy link
Copy Markdown
Contributor

closes: #75772

Description

Adds a --json flag to breeze ui check-translation-completeness that outputs a machine-readable JSON document on stdout without Rich ANSI styling or narration:

  • Extracted report data aggregation into build_completeness_report() returning { "languages": { ... }, "complete": bool }.
  • Preserved byte-identical terminal table formatting and exit code semantics when --json is omitted.
  • Suppressed Breeze local reproduction CI banners on stdout when running with --json using SKIP_LOCAL_REPRODUCTION.
  • Redirected informational narration to stderr when composing --json with --add-missing and --remove-unused.
  • Regenerated command help SVG documentation assets (output_ui_check-translation-completeness.svg and .txt).
  • Added comprehensive unit tests covering report structure, stdout purity under CI, language filtering, and composition with --add-missing / --remove-unused.

Was generative AI tooling used to co-author this PR?
  • NA

…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 aaiss0927 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@Alwaysgaurav1

Copy link
Copy Markdown
Contributor Author

Hi @aaiss0927,

Thank you for the thorough review and for providing the reproducible test probes!

I have pushed an update addressing all three points:

  1. Stdout redirection & fatal error replay: Adopted the breeze ci verify --json pattern using contextlib.redirect_stdout(...). Console narration is suppressed to an in-memory buffer (or streamed to stderr with --verbose). If the computation aborts (e.g. unsupported plural suffixes or malformed JSON), the captured narration is replayed to stderr in the finally block, keeping stdout completely pure for jq.
  2. Clean error handling for malformed locale files: Unreadable file narration is now captured by the stdout redirection rather than leaking to stdout.
  3. Preserved table mode behavior: Restored table mode's execution order so that --language validation occurs at the exact same step as upstream, ensuring byte-identical table output before exiting with status 2.
  4. Regression tests: Adopted your 3 test probes into dev/breeze/tests/test_ui_commands.py (all 48 tests passing).

@aaiss0927

Copy link
Copy Markdown
Contributor

Thanks @Alwaysgaurav1 — that was quick. I re-ran the acceptance probes from my review against 13699b9 and all three pass now; the complete semantics also still hold after the found_difference cleanup (dropping the or lang_missing OR-ing is safe because build_completeness_report derives has_missing from the summary itself). Nice work tightening the table-mode error path back to upstream order, too.

One observation for the record, since the two PRs will be compared: the fix goes beyond the verify --json pattern suggested in the review and closely matches #75831's implementation — the buffer/completed abort-replay in the finally block (which isn't in verify_commands.py; upstream discards the captured narration on abort) and the print_completeness_json / apply_translation_modifications structure are the same design, down to naming. That's fine — it's Apache-licensed, and behavioral convergence makes the maintainers' choice simpler — but provenance seemed worth noting.

With behavior now effectively equivalent, the substantive remaining difference is the output schema. The $GITHUB_STEP_SUMMARY follow-up (@aruadecarvalho on #75772) is building against the shape documented in #75831's "Output shape" section, so whichever PR lands, it would be good to settle on one schema before consumers ship.

@potiuk

potiuk commented Nov 1, 2026

Copy link
Copy Markdown
Member

Thanks for working on this, @Alwaysgaurav1. #75831 implements the same --json flag for #75772 and has been approved and queued for merge, so this one will be superseded once it lands. Could you close this PR? If something here isn't covered in #75831, a follow-up on top of it would be very welcome.


Drafted-by: Claude Code (Claude Opus 5); reviewed by @potiuk before posting

@Alwaysgaurav1

Alwaysgaurav1 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the update and review, @potiuk! Glad to see #75831 landed and #75772 is resolved. Everything looks well-covered, so I'm closing this PR now.

I'm currently working on my next PR for Airflow—whenever you have some time, I'd really appreciate your review and feedback on it once it's up!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Breeze: add --json output to check-translation-completeness

3 participants