File size: 5,336 Bytes
cc11e77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
 * intentParserDirectFix.test.ts — S478 DIRECT-FIX: intentParser gate per domande definitorie
 *
 * Copertura (20 test):
 *  Gruppo A — Domande definitorie → null (no tool pre-exec, risposta LLM diretta)
 *  Gruppo B — Query live legittime → tool corretto (web_search, get_weather, ecc.)
 *  Gruppo C — Pattern edge-case: "chi è attuale/in carica" → live (politica)
 *  Gruppo D — Domande storiche brevi → null
 *
 * SESSIONE: S478 — DIRECT_RESPONSE_MODE
 */

import { describe, it, expect } from "vitest";
import { detectIntent } from "@/lib/agentLoop/intentParser";

// ─── Gruppo A: Domande definitorie → null ─────────────────────────────────────

describe("S478: detectIntent — domande definitorie → null (no tool pre-exec)", () => {

  it("A-1. 'chi è Einstein?' → null (storico, LLM sa già)", () => {
    expect(detectIntent("chi è Einstein?")).toBeNull();
  });

  it("A-2. 'chi era Napoleone?' → null (_isHistoricalPerson)", () => {
    expect(detectIntent("chi era Napoleone?")).toBeNull();
  });

  it("A-3. 'cos'è il DNA?' → null (_isDefinitionalShort)", () => {
    expect(detectIntent("cos'è il DNA?")).toBeNull();
  });

  it("A-4. 'cosa è il quantum computing?' → null", () => {
    expect(detectIntent("cosa è il quantum computing?")).toBeNull();
  });

  it("A-5. 'cosa sono i quark?' → null", () => {
    expect(detectIntent("cosa sono i quark?")).toBeNull();
  });

  it("A-6. 'what is machine learning?' → null (_isDefinitionalShort EN)", () => {
    expect(detectIntent("what is machine learning?")).toBeNull();
  });

  it("A-7. 'what are neural networks?' → null", () => {
    expect(detectIntent("what are neural networks?")).toBeNull();
  });

  it("A-8. 'who is Marie Curie?' → null", () => {
    expect(detectIntent("who is Marie Curie?")).toBeNull();
  });

  it("A-9. 'who was Leonardo da Vinci?' → null (_isHistoricalPerson EN)", () => {
    expect(detectIntent("who was Leonardo da Vinci?")).toBeNull();
  });

  it("A-10. 'dimmi chi è Darwin' → null (_isInlineDefinitional)", () => {
    expect(detectIntent("dimmi chi è Darwin")).toBeNull();
  });

  it("A-11. 'sai chi è Tesla?' → null (_isInlineDefinitional)", () => {
    expect(detectIntent("sai chi è Tesla?")).toBeNull();
  });

  it("A-12. 'mi spieghi chi è Platone?' → null", () => {
    expect(detectIntent("mi spieghi chi è Platone?")).toBeNull();
  });

});

// ─── Gruppo B: Query live → tool corretto ─────────────────────────────────────

describe("S478: detectIntent — query live → tool corretto (non bloccato)", () => {

  it("B-1. 'meteo a Milano domani' → get_weather", () => {
    const r = detectIntent("meteo a Milano domani");
    expect(r?.tool).toBe("get_weather");
  });

  it("B-2. 'ultime notizie di oggi' → get_news", () => {
    const r = detectIntent("ultime notizie di oggi");
    expect(r?.tool).toBe("get_news");
  });

  it("B-3. 'quanto costa Bitcoin adesso?' → web_search o get_currency", () => {
    const r = detectIntent("quanto costa Bitcoin adesso?");
    expect(r).not.toBeNull();
    expect(["web_search", "get_currency", "math_eval"]).toContain(r?.tool);
  });

  it("B-4. 'chi ha vinto la Champions ieri sera?' → web_search (live: partita)", () => {
    const r = detectIntent("chi ha vinto la Champions ieri sera?");
    expect(r?.tool).toBe("web_search");
  });

  it("B-5. 'cerca su internet le ultime su OpenAI' → web_search (meta-search)", () => {
    const r = detectIntent("cerca su internet le ultime su OpenAI");
    expect(r?.tool).toBe("web_search");
  });

  it("B-6. 'genera un'immagine di un tramonto sul mare' → generate_image", () => {
    const r = detectIntent("genera un'immagine di un tramonto sul mare");
    expect(r?.tool).toBe("generate_image");
  });

});

// ─── Gruppo C: Edge case — "chi è attuale/in carica" → live ──────────────────

describe("S478: detectIntent — 'chi è attuale/in carica' = live, non bloccato", () => {

  it("C-1. 'chi è il presidente degli USA adesso?' → web_search (live: adesso)", () => {
    const r = detectIntent("chi è il presidente degli USA adesso?");
    expect(r?.tool).toBe("web_search");
  });

  it("C-2. 'chi è il governo attuale italiano?' → web_search (live: governo + attuale)", () => {
    const r = detectIntent("chi è il governo attuale italiano?");
    expect(r?.tool).toBe("web_search");
  });

  it("C-3. 'chi è in carica come ministro?' → web_search (live: in carica)", () => {
    const r = detectIntent("chi è in carica come ministro?");
    expect(r?.tool).toBe("web_search");
  });

});

// ─── Gruppo D: Math eval — non bloccato da guard definitorio ─────────────────

describe("S478: detectIntent — math eval non interferisce con guard", () => {

  it("D-1. '123 * 456' → math_eval (non bloccato da _isDefinitionalShort)", () => {
    const r = detectIntent("123 * 456");
    expect(r?.tool).toBe("math_eval");
  });

  it("D-2. 'calcola sqrt(144)' → math_eval", () => {
    const r = detectIntent("calcola sqrt(144)");
    expect(r?.tool).toBe("math_eval");
  });

});