AUDIT / src /lib /__tests__ /knowledgeGapBlockN8.test.ts
Arypulka98's picture
feat(audit): deploy full backend cluster node (part 2)
cc11e77 verified
Raw
History Blame Contribute Delete
3.12 kB
/**
* knowledgeGapBlockN8.test.ts — N8: EN signal patterns in KNOWLEDGE_GAP_SIGNALS
*
* knowledgeGapBlock.ts aveva KNOWLEDGE_GAP_SIGNALS solo in italiano.
* Se l'utente scrive in EN ("who is the current CEO?") nessun pattern matchava
* e l'agente non veniva forzato a usare web_search prima di rispondere.
* Fix: +9 pattern EN (temporal/version/price/person/statistics).
*/
import { describe, it, expect } from "vitest";
import { detectKnowledgeGap } from "@/lib/agentLoop/knowledgeGapBlock";
const CLS_GENERAL = { type: "general_qa", complexity: 5, isDirectAnswer: false };
const CLS_CODE = { type: "code_fix", complexity: 4, isDirectAnswer: false };
const CLS_RT = { type: "realtime_query", complexity: 5, isDirectAnswer: false };
// Query EN con gap di conoscenza — devono triggerare hasGap=true
const EN_GAP_QUERIES = [
"who is the current CEO of Apple?",
"who is the new prime minister of Italy?",
"what is the latest version of Node.js?",
"current version of Python?",
"what is the current price of Tesla stock?",
"how much does a MacBook Pro cost today?",
"how many users does Instagram have?",
"how many customers does Amazon have?",
"recent statistics on remote work adoption",
"latest report on climate change",
"what happened recently with SpaceX?",
"what is the market cap of Apple right now?",
];
// Query IT già presenti — no regression
const IT_GAP_QUERIES = [
"chi e' il presidente attuale degli USA?",
"quanto costa il Bitcoin oggi?",
"quanti utenti ha TikTok?",
"ultima versione di React?",
"statistica recente sul lavoro da remoto",
];
// Query tecnica pura a bassa complessita' — skip
const CODE_LOW = [
"fix this TypeScript error: cannot find module",
"correggi questo errore di build webpack",
];
// realtime_query — gia' gestita, non deve aggiungere hint ridondante
const REALTIME = [
"latest news about AI today",
"notizie di oggi sull'intelligenza artificiale",
];
describe("N8: detectKnowledgeGap riconosce query EN", () => {
it.each(EN_GAP_QUERIES)("EN gap query '%s' -> hasGap=true", (msg) => {
const result = detectKnowledgeGap(msg, CLS_GENERAL);
expect(result.hasGap).toBe(true);
expect(result.hint).not.toBe("");
});
it.each(IT_GAP_QUERIES)("IT query '%s' -> hasGap=true (no regression)", (msg) => {
const result = detectKnowledgeGap(msg, CLS_GENERAL);
expect(result.hasGap).toBe(true);
});
it.each(CODE_LOW)("code/build fix '%s' -> skip (bassa complessita')", (msg) => {
const result = detectKnowledgeGap(msg, CLS_CODE);
expect(result.hasGap).toBe(false);
});
it.each(REALTIME)("realtime_query '%s' -> skip (gia' gestita)", (msg) => {
const result = detectKnowledgeGap(msg, CLS_RT);
expect(result.hasGap).toBe(false);
});
it("N8-1: hint contiene [KNOWLEDGE GAP] tag", () => {
const result = detectKnowledgeGap("who is the current CEO of Tesla?", CLS_GENERAL);
expect(result.hint).toContain("[KNOWLEDGE GAP");
});
it("N8-2: null cls -> no gap", () => {
expect(detectKnowledgeGap("who is the CEO?", null).hasGap).toBe(false);
});
});