fix(cli): make lint-translations exit non-zero when translations differ - #2996
Open
Zuhef wants to merge 1 commit into
Open
fix(cli): make lint-translations exit non-zero when translations differ#2996Zuhef wants to merge 1 commit into
Zuhef wants to merge 1 commit into
Conversation
`chainlit lint-translations` reported differences and then exited 0, so it could not be used as a CI gate - which is how missing locale keys accumulate unnoticed. The chain was silent end to end: `lint_translation_json` printed the differences and returned None, `lint_translations` returned None, and the command ignored the result. On a checkout of main the command reports six real missing keys across the packaged locales and still exits 0. `lint_translation_json` now returns the differences it printed, and `lint_translations` returns the total count, so the command can fail. Both are additive: existing callers that ignore the return value are unaffected. Also dedent the per-file loop out of the ground-truth `with open(...)` block, which held that handle open for the whole run, and sort the directory listing so the report order is deterministic. Verified on Windows against a directory holding all 23 packaged locales: before, 6 differences reported and exit 0; after, the same 6 differences and exit 1. A clean directory still exits 0.
Zuhef
requested review from
asvishnyakov,
hayescode and
sandangel
as code owners
July 29, 2026 19:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
chainlit lint-translationsreports differences and then exits 0, so it cannot gate anything. Issue #2993 identified this as the reason locale keys drift unnoticed, and it is true even for the app translations the command is actually pointed at.The chain is silent end to end:
lint_translation_jsonprints the differences and returnsNonelint_translationsreturnsNonechainlit_lint_translationscalls it and ignores the result, so Click exits 0Change
lint_translation_jsonreturns the differences it printed. Additive - existing callers that ignore the return value are unaffected, and the printed output is unchanged.lint_translationsreturns the total count across all linted files.SystemExit(1)when the count is non-zero.Two incidental cleanups in the same function: the per-file loop was nested inside the ground-truth
with open(...)block, holding that handle open for the entire run, so it is dedented; andos.listdiris now sorted so the report order is deterministic. Happy to drop either if you would rather keep the diff to the exit code alone.Verification
Ran on Windows against a directory containing all 23 packaged locales, comparing a clean
mainworktree with the patched tree:mainSame six differences either way - only the exit code changes. A directory whose translations match the ground truth still exits 0.
The six it finds are the real gaps from #2993, which is a useful independent cross-check: this is the CLI path rather than the test suite, and it reports exactly
chat.favorites.remove(ar-SA, da-DK),components.DatePickerInput(de-DE, it, ko) andchat.fileUpload.browse(ja).pytest backend/tests/test_translations.py- 39 passed. New tests cover the returned error list, the aggregate count for both clean and broken input, and that non-JSON files in the directory are ignored.ruff format --checkclean on all four files.ruff checkreports two RUF036 findings atconfig.py:391-392, which are pre-existing and outside this change.Note
While verifying this I hit a separate pre-existing problem: on a stock Windows console the command dies with a
UnicodeEncodeErrorprinting the✅/❌markers, since the console code page cannot encode them. It only runs withPYTHONIOENCODING=utf-8set. That is independent of this change and I have not touched it here - happy to open a separate issue or PR for it if useful.Summary by cubic
Fix the CLI so
chainlit lint-translationsexits non-zero when any translation differs. This enables CI to fail on missing or extra keys and prevents locale drift.Bug Fixes
lint_translation_jsonnow returns the list of differences (printing unchanged).lint_translationsreturns the total difference count across files.Refactors
with open(...)block to avoid holding the file open.os.listdirfor deterministic reporting order.Written for commit f89b44b. Summary will update on new commits.