From 1c0d36eed009f11bb41f717a270d5b83872373cc Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 2 Mar 2026 04:24:01 +0000 Subject: [PATCH] fix(ci): resolve i18n typing and generated-policy drift --- .../HostEnvSecurityPolicy.generated.swift | 6 +++--- src/i18n/registry.test.ts | 16 ++++++++++++++-- ui/src/i18n/lib/registry.ts | 9 +++++---- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/apps/macos/Sources/OpenClaw/HostEnvSecurityPolicy.generated.swift b/apps/macos/Sources/OpenClaw/HostEnvSecurityPolicy.generated.swift index e4927331b4f..b126d03de21 100644 --- a/apps/macos/Sources/OpenClaw/HostEnvSecurityPolicy.generated.swift +++ b/apps/macos/Sources/OpenClaw/HostEnvSecurityPolicy.generated.swift @@ -22,17 +22,17 @@ enum HostEnvSecurityPolicy { "PS4", "GCONV_PATH", "IFS", - "SSLKEYLOGFILE", + "SSLKEYLOGFILE" ] static let blockedOverrideKeys: Set = [ "HOME", - "ZDOTDIR", + "ZDOTDIR" ] static let blockedPrefixes: [String] = [ "DYLD_", "LD_", - "BASH_FUNC_", + "BASH_FUNC_" ] } diff --git a/src/i18n/registry.test.ts b/src/i18n/registry.test.ts index afa868a1171..e05ba99e738 100644 --- a/src/i18n/registry.test.ts +++ b/src/i18n/registry.test.ts @@ -5,6 +5,18 @@ import { loadLazyLocaleTranslation, resolveNavigatorLocale, } from "../../ui/src/i18n/lib/registry.ts"; +import type { TranslationMap } from "../../ui/src/i18n/lib/types.ts"; + +function getNestedTranslation(map: TranslationMap | null, ...path: string[]): string | undefined { + let value: string | TranslationMap | undefined = map ?? undefined; + for (const key of path) { + if (value === undefined || typeof value === "string") { + return undefined; + } + value = value[key]; + } + return typeof value === "string" ? value : undefined; +} describe("ui i18n locale registry", () => { it("lists supported locales", () => { @@ -23,8 +35,8 @@ describe("ui i18n locale registry", () => { const de = await loadLazyLocaleTranslation("de"); const zhCN = await loadLazyLocaleTranslation("zh-CN"); - expect(de?.common?.health).toBe("Status"); - expect(zhCN?.common?.health).toBe("健康状况"); + expect(getNestedTranslation(de, "common", "health")).toBe("Status"); + expect(getNestedTranslation(zhCN, "common", "health")).toBe("健康状况"); expect(await loadLazyLocaleTranslation("en")).toBeNull(); }); }); diff --git a/ui/src/i18n/lib/registry.ts b/ui/src/i18n/lib/registry.ts index e05d5942692..341f27e213c 100644 --- a/ui/src/i18n/lib/registry.ts +++ b/ui/src/i18n/lib/registry.ts @@ -37,6 +37,10 @@ export function isSupportedLocale(value: string | null | undefined): value is Lo return value !== null && value !== undefined && SUPPORTED_LOCALES.includes(value as Locale); } +function isLazyLocale(locale: Locale): locale is LazyLocale { + return LAZY_LOCALES.includes(locale as LazyLocale); +} + export function resolveNavigatorLocale(navLang: string): Locale { if (navLang.startsWith("zh")) { return navLang === "zh-TW" || navLang === "zh-HK" ? "zh-TW" : "zh-CN"; @@ -51,13 +55,10 @@ export function resolveNavigatorLocale(navLang: string): Locale { } export async function loadLazyLocaleTranslation(locale: Locale): Promise { - if (locale === DEFAULT_LOCALE) { + if (!isLazyLocale(locale)) { return null; } const registration = LAZY_LOCALE_REGISTRY[locale]; - if (!registration) { - return null; - } const module = await registration.loader(); return module[registration.exportName] ?? null; }