Files
orca/config/scripts/locale-repair-catalog-missing-leaves.test.mjs
T
Turtle-HwanandOrca f9a5920954 fix(i18n): stop repairCatalog crashing on un-bootstrapped locale keys (#11728)
en.json carries ~190 keys per locale that the locale catalogs have not been
bootstrapped with yet, so every repair-locale-catalog run threw a TypeError
before doing any work. Skip missing leaves instead.

Split out of #11728 so the crash fix can land without the catalog
regeneration, which still needs native-speaker review.

Co-authored-by: Turtle-Hwan <turtlehwan@gmail.com>

Co-authored-by: Orca <help@stably.ai>
2026-08-04 03:56:33 -07:00

31 lines
1.2 KiB
JavaScript

import { describe, expect, it } from 'vitest'
import { repairCatalog } from './locale-translation-policy.mjs'
// Regression: en.json routinely carries keys a locale catalog has not been bootstrapped with yet
// (~190 per locale at the time of writing), which crashed the whole repair run before it did any work.
describe('repairCatalog with un-bootstrapped keys', () => {
const enCatalog = {
auto: {
lib: { agent: { catalog: { '760bc6883d': 'Codex' } } },
components: { untranslated: 'Continue', nested: { alsoMissing: 'Refresh' } }
}
}
const translatedOnly = () => ({ auto: { lib: { agent: { catalog: { '760bc6883d': '사본' } } } } })
it('skips leaves the locale catalog is missing instead of throwing', () => {
for (const locale of ['ko', 'ja', 'zh', 'es']) {
const localeCatalog = translatedOnly()
expect(() => repairCatalog(enCatalog, localeCatalog, locale), locale).not.toThrow()
expect(localeCatalog.auto.components, locale).toBeUndefined()
}
})
it('still repairs the leaves that are present', () => {
const localeCatalog = translatedOnly()
expect(repairCatalog(enCatalog, localeCatalog, 'ko')).toBe(1)
expect(localeCatalog.auto.lib.agent.catalog['760bc6883d']).toBe('Codex')
})
})