-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathempty-hint.test.ts
More file actions
56 lines (47 loc) · 2 KB
/
Copy pathempty-hint.test.ts
File metadata and controls
56 lines (47 loc) · 2 KB
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
import { describe, it, expect } from "vitest";
import { withEmptyHint } from "./empty-hint.js";
import type { ToolResult } from "../tools/types.js";
const empty = (hint?: string): ToolResult => ({ rows: [], columns: ["a"], hint });
const filled = (hint?: string): ToolResult => ({ rows: [{ a: "1" }], columns: ["a"], hint });
// Riproduce la risoluzione del path MCP (server.ts formatResult, escluso DEFAULT_EMPTY)
const mcpHint = (result: ToolResult, emptyHint?: string) => result.hint ?? emptyHint;
describe("withEmptyHint", () => {
it("risultato vuoto senza hint dinamico usa l'emptyHint statico", () => {
const out = withEmptyHint(empty(), "STATICO");
expect(out.hint).toBe("STATICO");
expect(out.rows).toEqual([]);
});
it("l'hint dinamico ha precedenza sull'emptyHint statico", () => {
const out = withEmptyHint(empty("DINAMICO"), "STATICO");
expect(out.hint).toBe("DINAMICO");
});
it("risultato non vuoto non riceve alcun hint", () => {
const out = withEmptyHint(filled(), "STATICO");
expect(out.hint).toBeUndefined();
});
it("vuoto senza hint dinamico né emptyHint non produce hint", () => {
const out = withEmptyHint(empty(), undefined);
expect(out.hint).toBeUndefined();
});
it("non muta l'oggetto risultato in ingresso", () => {
const input = empty();
const out = withEmptyHint(input, "STATICO");
expect(input.hint).toBeUndefined();
expect(out).not.toBe(input);
});
it("hint dinamico stringa vuota (falsy ma non nullish) non viene sovrascritto", () => {
const out = withEmptyHint(empty(""), "STATICO");
expect(out.hint).toBe("");
});
it("parità con il path MCP (result.hint ?? emptyHint)", () => {
const cases: Array<[ToolResult, string | undefined]> = [
[empty(), "STATICO"],
[empty("DINAMICO"), "STATICO"],
[empty(""), "STATICO"],
[empty(), undefined],
];
for (const [result, emptyHint] of cases) {
expect(withEmptyHint(result, emptyHint).hint).toBe(mcpHint(result, emptyHint));
}
});
});