- Adjusted formatting in conversationContext.ts for better token estimation readability. - Enhanced readability in indonesianTextNormalizer.ts by formatting multiline replacements. - Reformatted badword lists and whitelists in indonesianTextNormalizer.ts for consistency. - Improved function signatures in messageStore.ts for clarity. - Reformatted messageCapture.ts to enhance readability of channel ID checks. - Cleaned up error logging in messageStore.ts and retentionManager.ts for better clarity. - Reformatted indonesianSlangLexicon.ts for consistent object formatting. - Enhanced URL fetching regex patterns in urlFetcher.ts for better readability. - Simplified query parameter destructuring in analyticsRoutes.ts for cleaner code. - Improved test readability in autoDeleteManager.test.ts and indonesianTextNormalizer.test.ts by formatting expectations. - Cleaned up whitespace in messageCaptureFilter.test.ts for consistency.
99 lines
3.6 KiB
TypeScript
99 lines
3.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
buildModerationTextEvidence,
|
|
detectIndonesianBadwords,
|
|
formatModerationTextEvidenceForPrompt,
|
|
normalizeDiscordCustomEmoji,
|
|
normalizeIndonesianSlang,
|
|
} from "../../src/moderation/indonesianTextNormalizer";
|
|
|
|
describe("normalizeDiscordCustomEmoji", () => {
|
|
it("replaces static custom emoji", () => {
|
|
const result = normalizeDiscordCustomEmoji(
|
|
"Bersiaplah woy <:hadeh:1217434294281048185>",
|
|
);
|
|
expect(result.text).toBe("Bersiaplah woy [emoji:hadeh]");
|
|
expect(result.emojiNames).toContain("hadeh");
|
|
});
|
|
|
|
it("replaces animated custom emoji", () => {
|
|
const result = normalizeDiscordCustomEmoji("cek <a:speen:1234567890> dulu");
|
|
expect(result.text).toBe("cek [emoji:speen] dulu");
|
|
expect(result.emojiNames).toContain("speen");
|
|
});
|
|
|
|
it("handles text without emoji", () => {
|
|
const result = normalizeDiscordCustomEmoji("halo semua");
|
|
expect(result.text).toBe("halo semua");
|
|
expect(result.emojiNames).toHaveLength(0);
|
|
});
|
|
});
|
|
|
|
describe("normalizeIndonesianSlang", () => {
|
|
it("maps common slang to normalized form", () => {
|
|
const { text, notes } = normalizeIndonesianSlang("gw emg kyk gitu");
|
|
expect(text).toBe("gue memang kayak gitu");
|
|
expect(notes.some((n) => n.startsWith("gw="))).toBe(true);
|
|
});
|
|
|
|
it("marks woy as safe casual interjection", () => {
|
|
const { text, notes } = normalizeIndonesianSlang("woy hadeh");
|
|
expect(text).toBe("woy hadeh");
|
|
expect(notes.some((n) => n.includes("casual"))).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("detectIndonesianBadwords", () => {
|
|
it("detects known badword via local fallback", async () => {
|
|
const badwords = await detectIndonesianBadwords("kontol banget");
|
|
expect(badwords).toContain("kontol");
|
|
});
|
|
|
|
it("returns empty array for safe slang", async () => {
|
|
const badwords = await detectIndonesianBadwords("woy hadeh gua");
|
|
expect(badwords).toHaveLength(0);
|
|
});
|
|
});
|
|
|
|
describe("buildModerationTextEvidence", () => {
|
|
it("produces correct evidence for woy with emoji", async () => {
|
|
const evidence = await buildModerationTextEvidence(
|
|
"Bersiaplah woy <:hadeh:1217434294281048185>",
|
|
);
|
|
expect(evidence.normalized).toContain("[emoji:hadeh]");
|
|
expect(evidence.badwords).toHaveLength(0);
|
|
expect(evidence.hasBadwords).toBe(false);
|
|
expect(
|
|
evidence.notes.some((n) => n.includes("no Indonesian badword")),
|
|
).toBe(true);
|
|
expect(evidence.notes.some((n) => n.includes("emoji:hadeh"))).toBe(true);
|
|
expect(evidence.notes.some((n) => n.includes("casual"))).toBe(true);
|
|
});
|
|
|
|
it("detects badword when present", async () => {
|
|
const evidence = await buildModerationTextEvidence("anjing loe kontol");
|
|
expect(evidence.hasBadwords).toBe(true);
|
|
expect(evidence.notes.some((n) => n.includes("badword detected"))).toBe(
|
|
true,
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("formatModerationTextEvidenceForPrompt", () => {
|
|
it("returns prompt evidence for slang + emoji", async () => {
|
|
const formatted = await formatModerationTextEvidenceForPrompt(
|
|
"Bersiaplah woy <:hadeh:1217434294281048185>",
|
|
);
|
|
expect(formatted).toContain("[normalized_text:");
|
|
expect(formatted).toContain("[emoji:hadeh]");
|
|
expect(formatted).toContain("[normalization_notes:");
|
|
expect(formatted).toContain("no Indonesian badword detected");
|
|
});
|
|
|
|
it("includes normalized text even for clean input", async () => {
|
|
const formatted = await formatModerationTextEvidenceForPrompt("Halo semua");
|
|
expect(formatted).toContain("[normalized_text:");
|
|
expect(formatted).toContain("no Indonesian badword detected");
|
|
});
|
|
});
|