executive-ai/test/glossary.test.ts
Peppa 56cba4cad0 EA-1: приложение — подключение календаря Google и список дел на 7 дней
Сервер на Hono, клиент Google и его мок, переводы ru/kk/en, тесты по сценариям,
проверки и деплой (Dockerfile, /healthz).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-16 12:29:10 +05:00

48 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
import en from "../src/locales/en.json" with { type: "json" };
import kk from "../src/locales/kk.json" with { type: "json" };
import ru from "../src/locales/ru.json" with { type: "json" };
/** Слова из колонки «Нельзя» словаря docs/glossary.md. */
function bannedWords(): string[] {
const lines = readFileSync(new URL("../docs/glossary.md", import.meta.url), "utf8").split("\n");
return lines
.filter(
(line) => line.startsWith("|") && !line.startsWith("|---") && !line.startsWith("| Понятие"),
)
.flatMap((line) => (line.split("|")[3] ?? "").split(","))
.map((word) => word.trim())
.filter(Boolean);
}
function findBanned(text: string, banned: string[]): string[] {
return banned.filter((word) => {
const escaped = word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
return new RegExp(`(?<![\\p{L}\\p{N}])${escaped}(?![\\p{L}\\p{N}])`, "iu").test(text);
});
}
describe("тексты экрана и словарь", () => {
const banned = bannedWords();
it("словарь читается", () => {
expect(banned).toContain("стори");
expect(banned).toContain("мок");
});
it.each([
["ru", ru],
["kk", kk],
["en", en],
])("в текстах %s нет слов из колонки «Нельзя»", (_name, file) => {
for (const [key, value] of Object.entries(file)) {
expect(findBanned(value, banned), `${key}: ${value}`).toEqual([]);
}
});
it("русские тексты обращаются на «вы» со строчной буквы", () => {
for (const value of Object.values(ru)) expect(value).not.toMatch(/(?<![.!?] |^)Вы(?![\p{L}])/u);
});
});