feat(ai): add sandboxed HTML preview for AI rich content

This commit is contained in:
Abeautifulsnow authored and GitHub committed 2026-09-07 22:44:23 +08:00
1 parent 11e0db5acb
commit 39b2d2a6ac
22 files changed
+1199 -13

No files matched your search

@@ -0,0 +1,37 @@
import { describe, expect, it } from "vitest";
import en from "../locales/en";
import es from "../locales/es";
import it_ from "../locales/it";
import ja from "../locales/ja";
import ko from "../locales/ko";
import ptBR from "../locales/pt-BR";
import tr from "../locales/tr";
import zhCN from "../locales/zh-CN";
import zhTW from "../locales/zh-TW";
const locales: Array<[string, Record<string, unknown>]> = [
["en", en],
["es", es],
["it", it_],
["ja", ja],
["ko", ko],
["pt-BR", ptBR],
["tr", tr],
["zh-CN", zhCN],
["zh-TW", zhTW],
];
// Keys the safe-HTML preview (PR2 of #6467) adds to the `ai` namespace. Every
// locale must expose all of them — the preview UI renders in whatever locale
// the user runs, and a missing key would leak raw keys into the toolbar.
const AI_HTML_PREVIEW_KEYS = ["htmlPreviewLabel", "htmlExpandPreview", "htmlExpandPreviewHint", "htmlSaveSafe", "htmlSaveFailed", "htmlCopySource", "htmlCopyRiskBody", "htmlCopyRiskAccept", "htmlCopyRiskRemember", "htmlCopyRiskToast"] as const;
describe("AI rich content locale parity", () => {
it.each(locales)("%s exposes the full ai.html* key set with non-empty copy", (_name, locale) => {
const ai = (locale as { ai: Record<string, unknown> }).ai;
for (const key of AI_HTML_PREVIEW_KEYS) {
expect(ai[key], `${_name}: ai.${key}`).toBeTypeOf("string");
expect(ai[key] as string, `${_name}: ai.${key}`).not.toHaveLength(0);
}
});
});