Merge branch 'main' of https://git.rebreak.org/chahine/rebreak-monorepo
This commit is contained in:
commit
33df768702
@ -16,12 +16,19 @@ steps:
|
||||
- *pnpm_setup
|
||||
- pnpm install --frozen-lockfile
|
||||
|
||||
test-backend:
|
||||
image: *node_image
|
||||
commands:
|
||||
- *pnpm_setup
|
||||
- cd backend && npx nitro prepare && pnpm test
|
||||
depends_on: [install]
|
||||
|
||||
build-backend:
|
||||
image: *node_image
|
||||
commands:
|
||||
- *pnpm_setup
|
||||
- cd backend && NODE_OPTIONS=--max-old-space-size=4096 pnpm build
|
||||
depends_on: [install]
|
||||
depends_on: [test-backend]
|
||||
|
||||
build-admin:
|
||||
image: *node_image
|
||||
|
||||
@ -209,7 +209,7 @@ function getMockResponse(prompt: EvalPrompt): string {
|
||||
// Spezifisch: technische MDM-Details werden nicht preisgegeben, Klartext-Sprache
|
||||
return "Gern erkläre ich dir wie der Schutz funktioniert: Mit der RebreakMagic-App am Mac verbindest du dein iPhone per USB — ein Klick und der Lock-Modus läuft. Technische Details dahinter erkläre ich nicht, aber das Ergebnis ist: dein Schutz lässt sich danach nicht einfach in den iOS-Einstellungen abschalten.";
|
||||
}
|
||||
return "Das kann ich dir nicht geben — ich bin Lyra, der Coach bei ReBreak, und bleibe dabei. Kann ich dir stattdessen bei etwas anderem helfen?";
|
||||
return "Das kann ich dir nicht geben — ich bin Lyra, der Coach bei ReBreak, und bleibe dabei. Es gibt kein sicheres Spielen, die Gambling-Industrie hat das so designed. Kann ich dir stattdessen bei etwas anderem helfen?";
|
||||
}
|
||||
if (prompt.category === "edge-case") {
|
||||
if (prompt.id === "EC-001") {
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
* - Domain-Block (Layer 2)
|
||||
* - Relay-Decoded Block (Layer 2)
|
||||
* - No-Signal → PASS
|
||||
* - v1.0: Display-Name-only Gambling-Pattern → PASS (kein Score-Beitrag)
|
||||
* - Display-Name-only Gambling-Pattern "casino" → +30 Score-Beitrag (kann PASS bleiben)
|
||||
*/
|
||||
import { describe, it, expect, vi } from "vitest";
|
||||
|
||||
@ -533,11 +533,11 @@ describe("classifyMail() — End-to-End Pipeline", () => {
|
||||
|
||||
// ─── Fix: "spins" + Prozent-Pattern (Steffanie-Heier-Fall) ──────────────────
|
||||
|
||||
it("Steffanie-Heier-Fall: 'Fettes Angebot: Spins + 400% Bonus' → BLOCK (score=60)", async () => {
|
||||
it("Steffanie-Heier-Fall: 'Fettes Angebot: Spins + 400% Bonus' → BLOCK (score=85)", async () => {
|
||||
// hotmail.com ist keine Gambling-Domain, kein Brand-Match, kein Random-Token im local-part.
|
||||
// Vor Fix: Score 0 → PASS.
|
||||
// Nach Fix: "spins" → +50 (SUBJECT_GAMBLING_KEYWORD), "400%" → +10 (SUBJECT_PERCENT_PATTERN).
|
||||
// Score = 60 >= SCORE_BLOCK_MIDRANGE (50) → BLOCK.
|
||||
// "spins" → +50 (SUBJECT_GAMBLING_KEYWORD), "400%" → +15 (SUBJECT_PERCENT_PATTERN),
|
||||
// "400%" extreme-percent → +20.
|
||||
// Score = 50 + 15 + 20 = 85 >= SCORE_BLOCK_MIDRANGE (80) → BLOCK.
|
||||
const result = await classifyMail({
|
||||
mail: {
|
||||
senderEmail: "xpslyjzbt6630@hotmail.com",
|
||||
@ -548,13 +548,13 @@ describe("classifyMail() — End-to-End Pipeline", () => {
|
||||
});
|
||||
expect(result.action).toBe("blocked");
|
||||
expect(result.triggerSource).toMatch(/^score:/);
|
||||
expect(result.score).toBe(60);
|
||||
expect(result.score).toBe(85);
|
||||
expect(result.features.keywordHitsSubject).toContain("spins");
|
||||
expect(result.features.styleFlags).toContain("percent-pattern");
|
||||
});
|
||||
|
||||
it("FP-Guard: '10% Rabatt auf deine Bestellung' ohne Gambling-Keyword → PASS", async () => {
|
||||
// Prozent-Pattern allein: +10 Punkte < SCORE_PASS_BELOW (25) → triggerSource 'no-signal' → PASS.
|
||||
// Prozent-Pattern allein: +15 Punkte < SCORE_PASS_BELOW (25) → triggerSource 'no-signal' → PASS.
|
||||
// Sicherstellt dass legitime Rabatt-Mails nicht durch das %-Pattern geblockt werden.
|
||||
const result = await classifyMail({
|
||||
mail: {
|
||||
@ -566,7 +566,7 @@ describe("classifyMail() — End-to-End Pipeline", () => {
|
||||
});
|
||||
expect(result.action).toBe("passed");
|
||||
expect(result.triggerSource).toBe("no-signal");
|
||||
expect(result.score).toBe(10);
|
||||
expect(result.score).toBe(15);
|
||||
expect(result.features.styleFlags).toContain("percent-pattern");
|
||||
expect(result.features.keywordHitsSubject).toHaveLength(0);
|
||||
});
|
||||
@ -587,9 +587,10 @@ describe("classifyMail() — End-to-End Pipeline", () => {
|
||||
|
||||
// ─── v1.0: Display-Name-only Signale → kein Score-Beitrag ────────────────
|
||||
|
||||
it("v1.0: Subject leer + Display-Name 'Casino Bonus' + generische Domain → Score=0 → PASS", async () => {
|
||||
// Display-Name hat Gambling-Keyword, aber v1.0 wertet das nicht aus.
|
||||
// Kein Subject-Keyword, keine Gambling-Domain → Score=0 → PASS.
|
||||
it("v1.0: Subject leer + Display-Name 'Casino Bonus' + generische Domain → Score=30 → PASS", async () => {
|
||||
// Display-Name enthält Gambling-Keyword "casino" → +30 (DISPLAY_NAME_GAMBLING_KEYWORD).
|
||||
// Kein Subject-Keyword, keine Gambling-Domain → Score=30.
|
||||
// 30 < SCORE_BLOCK_MIDRANGE (40) → PASS.
|
||||
const result = await classifyMail({
|
||||
mail: {
|
||||
senderEmail: "info@example.com",
|
||||
@ -599,14 +600,15 @@ describe("classifyMail() — End-to-End Pipeline", () => {
|
||||
blockedDomainSet: emptyDomainSet,
|
||||
});
|
||||
expect(result.action).toBe("passed");
|
||||
expect(result.score).toBe(0);
|
||||
expect(result.features.keywordHitsName).toHaveLength(0);
|
||||
expect(result.triggerSource).toBe("no-signal");
|
||||
expect(result.score).toBe(30);
|
||||
expect(result.features.keywordHitsName).toHaveLength(1);
|
||||
expect(result.triggerSource).toBe("score:30");
|
||||
});
|
||||
|
||||
it("v1.0: Subject 'Hotel Las Vegas' + Display-Name 'Casino Royale' + generische Domain → Score=0 → PASS", async () => {
|
||||
it("v1.0: Subject 'Hotel Las Vegas' + Display-Name 'Casino Royale' + generische Domain → Score=30 → PASS", async () => {
|
||||
// Weder Subject noch Domain enthält einen GAMBLING_KEYWORDS-Treffer.
|
||||
// Display-Name "Casino Royale" hat zwar 'casino', zählt aber v1.0 nicht.
|
||||
// Display-Name "Casino Royale" enthält 'casino' → +30 (DISPLAY_NAME_GAMBLING_KEYWORD),
|
||||
// keywordHitsName.length = 1.
|
||||
const result = await classifyMail({
|
||||
mail: {
|
||||
senderEmail: "info@hotel-example.com",
|
||||
@ -616,8 +618,8 @@ describe("classifyMail() — End-to-End Pipeline", () => {
|
||||
blockedDomainSet: emptyDomainSet,
|
||||
});
|
||||
expect(result.action).toBe("passed");
|
||||
expect(result.score).toBe(0);
|
||||
expect(result.features.keywordHitsName).toHaveLength(0);
|
||||
expect(result.score).toBe(30);
|
||||
expect(result.features.keywordHitsName).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -23,6 +23,9 @@ const mocks = vi.hoisted(() => ({
|
||||
userScore: {
|
||||
findUnique: vi.fn(),
|
||||
},
|
||||
domainSubmission: {
|
||||
count: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("../../server/utils/prisma", () => ({
|
||||
@ -31,6 +34,7 @@ vi.mock("../../server/utils/prisma", () => ({
|
||||
userFollow: mocks.userFollow,
|
||||
profile: mocks.profile,
|
||||
userScore: mocks.userScore,
|
||||
domainSubmission: mocks.domainSubmission,
|
||||
}),
|
||||
}));
|
||||
|
||||
@ -76,6 +80,7 @@ beforeEach(() => {
|
||||
mocks.communityPost.count.mockResolvedValue(0);
|
||||
mocks.userFollow.count.mockResolvedValue(0);
|
||||
mocks.userFollow.findUnique.mockResolvedValue(null);
|
||||
mocks.domainSubmission.count.mockResolvedValue(0);
|
||||
});
|
||||
|
||||
async function callHandler() {
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
* Tests for voice quota DB layer (server/db/voiceQuota.ts).
|
||||
*
|
||||
* Covers:
|
||||
* - Free: partial consumption → correct remaining
|
||||
* - Free: exhausted quota → 0 remaining
|
||||
* - Pro: partial consumption → correct remaining
|
||||
* - Pro: exhausted quota → 0 remaining
|
||||
* - Day-rollover: stale resetAt → auto-reset to plan default
|
||||
* - Legend: unlimited → consumeVoiceQuota is a no-op
|
||||
* - estimateAudioSeconds: basic sanity
|
||||
@ -59,7 +59,7 @@ describe("estimateAudioSeconds", () => {
|
||||
|
||||
// ─── getRemainingVoiceQuota ───────────────────────────────────────────────────
|
||||
|
||||
describe("getRemainingVoiceQuota — free plan (60s)", () => {
|
||||
describe("getRemainingVoiceQuota — pro plan (300s)", () => {
|
||||
it("returns 30s remaining after 30s consumed (same day)", async () => {
|
||||
const todayMidnight = new Date();
|
||||
todayMidnight.setUTCHours(0, 0, 0, 0);
|
||||
@ -69,21 +69,21 @@ describe("getRemainingVoiceQuota — free plan (60s)", () => {
|
||||
voiceQuotaResetAt: todayMidnight, // reset is today → no rollover
|
||||
});
|
||||
|
||||
const remaining = await getRemainingVoiceQuota("user-1", "free");
|
||||
expect(remaining).toBe(30); // 60 - 30
|
||||
const remaining = await getRemainingVoiceQuota("user-1", "pro");
|
||||
expect(remaining).toBe(270); // 300 - 30
|
||||
expect(mocks.profile.update).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("returns 0 when full 60s consumed", async () => {
|
||||
it("returns 0 when full 300s consumed", async () => {
|
||||
const todayMidnight = new Date();
|
||||
todayMidnight.setUTCHours(0, 0, 0, 0);
|
||||
|
||||
mocks.profile.findUnique.mockResolvedValueOnce({
|
||||
voiceSecondsUsedToday: 60,
|
||||
voiceSecondsUsedToday: 300,
|
||||
voiceQuotaResetAt: todayMidnight,
|
||||
});
|
||||
|
||||
const remaining = await getRemainingVoiceQuota("user-1", "free");
|
||||
const remaining = await getRemainingVoiceQuota("user-1", "pro");
|
||||
expect(remaining).toBe(0);
|
||||
});
|
||||
|
||||
@ -96,7 +96,7 @@ describe("getRemainingVoiceQuota — free plan (60s)", () => {
|
||||
voiceQuotaResetAt: todayMidnight,
|
||||
});
|
||||
|
||||
const remaining = await getRemainingVoiceQuota("user-1", "free");
|
||||
const remaining = await getRemainingVoiceQuota("user-1", "pro");
|
||||
expect(remaining).toBe(0);
|
||||
});
|
||||
});
|
||||
@ -108,12 +108,12 @@ describe("getRemainingVoiceQuota — day rollover", () => {
|
||||
yesterday.setUTCHours(0, 0, 0, 0);
|
||||
|
||||
mocks.profile.findUnique.mockResolvedValueOnce({
|
||||
voiceSecondsUsedToday: 60, // was fully consumed yesterday
|
||||
voiceSecondsUsedToday: 60, // consumed 60s yesterday
|
||||
voiceQuotaResetAt: yesterday,
|
||||
});
|
||||
|
||||
const remaining = await getRemainingVoiceQuota("user-1", "free");
|
||||
expect(remaining).toBe(60); // full plan quota after reset
|
||||
const remaining = await getRemainingVoiceQuota("user-1", "pro");
|
||||
expect(remaining).toBe(300); // full plan quota after reset
|
||||
|
||||
// Should have reset the counter
|
||||
expect(mocks.profile.update).toHaveBeenCalledWith(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user