Wang1rrr opened a new pull request, #4809:
URL: https://github.com/apache/rocketmq-dashboard/pull/4809

   ### Which Issue(s) This PR Fixes
   
   No issue - test infrastructure for the localization work in #4621, #4629, 
#4633, #4802, #4803 and #4806.
   
   ### Brief Description
   
   `LangContext.t()` falls back to returning the key when the dictionary has no 
entry:
   
   ```ts
   let text = translations[key]?.[lang] ?? key;
   ```
   
   That fallback is the right runtime behaviour, but it means a misspelled, 
renamed or dropped key renders as raw text (`audit.exportFailed`) in the 
console and **every test still passes**. Nothing in the type system connects a 
`t('...')` call to an entry, because the dictionary is a `Record<string, ...>` 
keyed by string. The existing `LangContext.test.tsx` asserts that fallback 
exists; nothing asserts that it is never hit.
   
   This adds `web/src/i18n/__tests__/translations.test.ts` with the two 
invariants that make the failure loud:
   
   1. **Every entry carries a non-empty `zh` and `en` value** - a half-added 
key cannot ship a blank label in one locale.
   2. **Every literal key any non-test source hands to `t()` resolves** - the 
sources are read as text through `import.meta.glob(..., { query: '?raw' })` 
rather than walked as modules, so the check also covers branches no test 
renders. Test files are skipped because they mock the language context and 
invent keys on purpose.
   
   Template keys such as `` t(`audit.op.${code}`) `` cannot be resolved 
statically and are out of scope; the families they compose from are already 
covered by `constants/__tests__/theme.test.ts` and the audit-presentation 
lookups.
   
   ### How Did You Test This Change?
   
   Both invariants were verified to fail when the property is broken, so 
neither passes vacuously:
   
   ```
   # unknown key - added web/src/__invariant_probe.ts containing 
t('definitely.not.a.real.key')
   AssertionError: literal keys with no dictionary entry: expected [ Array(1) ] 
to deeply equal []
   +   "definitely.not.a.real.key <- ../../__invariant_probe.ts",
    Tests  1 failed | 1 passed (2)
   
   # empty locale - set the en value of common.close to ''
   AssertionError: entries missing a locale: expected [ 'common.close' ] to 
deeply equal []
   +   "common.close",
    Tests  1 failed | 1 passed (2)
   ```
   
   The probe file was deleted and `translations.ts` restored afterwards; 
neither mutation is part of this diff.
   
   Clean run:
   
   ```
   cd web
   npx vitest run src/i18n/__tests__/translations.test.ts
    Test Files  1 passed (1)
         Tests  2 passed (2)
   
   npx tsc -b                                                  # exit 0
   npx eslint src/i18n/__tests__/translations.test.ts          # exit 0
   npx prettier --check src/i18n/__tests__/translations.test.ts # clean
   ```
   
   Current coverage of the scan: 1881 literal `t()` call sites across 183 
non-test source files, reconciled against 2177 dictionary entries - all 
resolve. Baseline for reference: `npm test` on the trunk gives 139 files / 1280 
tests passing; this adds one file and two tests.
   
   ### Checklist
   
   - [x] One coherent change; unrelated modifications are not bundled in
   - [x] Commit subject follows Conventional Commits (`feat:` / `fix:` / 
`refactor:` / `chore:` / `docs:` / `perf:`)
   - [x] Tests added or updated for non-trivial changes, test methods named 
`...Test`
   - [ ] New UI text has both Chinese and English entries under `web/src/i18n/` 
- N/A, adds no UI text
   - [ ] Architecture constraints stay green (`mvn test` runs the ArchUnit 
checks) - N/A, frontend only
   - [x] New source files carry the ASF license header
   - [ ] Documentation touched where behaviour changed - N/A, no behaviour 
changed
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to