fix(cli): make lint-translations exit non-zero when translations differ - #2996
Open
Zuhef wants to merge 2 commits into
Open
fix(cli): make lint-translations exit non-zero when translations differ#2996Zuhef wants to merge 2 commits into
Zuhef wants to merge 2 commits 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
Collaborator
|
@codex review |
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the translation linter so translation differences can reliably fail CI.
Changes:
- Returns detected differences and aggregates their count.
- Produces deterministic file ordering.
- Exits with status 1 and prints a summary when differences exist.
- Adds coverage for return values, counting, and file filtering.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
backend/chainlit/translations.py |
Returns detected structural differences. |
backend/chainlit/config.py |
Aggregates differences across sorted translation files. |
backend/chainlit/cli/__init__.py |
Exits non-zero when differences are found. |
backend/tests/test_translations.py |
Tests difference reporting and aggregation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
dokterbob
enabled auto-merge
August 17, 2026 17:16
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Aug 17, 2026
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
Make
chainlit lint-translationsfail fast when translations differ. Previously it printed differences and exited 0; now it exits 1 so CI can gate locale changes.lint_translation_jsonreturns the list of differences (printed output unchanged).lint_translationsreturns the total difference count and sorts the directory listing for deterministic reports.with open(...)block to avoid holding the handle open.Written for commit af2f7ad. Summary will update on new commits.