-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathposthogExecDisplay.test.ts
More file actions
108 lines (94 loc) · 3.07 KB
/
Copy pathposthogExecDisplay.test.ts
File metadata and controls
108 lines (94 loc) · 3.07 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
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
import {
formatPosthogExecBody,
getPostHogExecDisplay,
isPostHogExecTool,
} from "@posthog/core/sessions/posthogExecDisplay";
import { describe, expect, it } from "vitest";
describe("isPostHogExecTool", () => {
it("matches the bare posthog exec tool", () => {
expect(isPostHogExecTool("mcp__posthog__exec")).toBe(true);
});
it("matches plugin-prefixed variants", () => {
expect(isPostHogExecTool("mcp__posthog_posthog__exec")).toBe(true);
expect(isPostHogExecTool("mcp__plugin_posthog_posthog__exec")).toBe(true);
expect(isPostHogExecTool("mcp__posthog_cloud__exec")).toBe(true);
});
it("rejects other MCP tools", () => {
expect(isPostHogExecTool("mcp__posthog__list")).toBe(false);
expect(isPostHogExecTool("mcp__other__exec")).toBe(false);
expect(isPostHogExecTool("Bash")).toBe(false);
});
});
describe("getPostHogExecDisplay", () => {
it("collapses `call <tool>` to the bare sub-tool label", () => {
expect(getPostHogExecDisplay({ command: "call experiment-list" })).toEqual({
label: "experiment-list",
input: undefined,
});
});
it("uses the JSON args portion as input", () => {
expect(
getPostHogExecDisplay({
command: 'call execute-sql {"query":"SELECT 1"}',
}),
).toEqual({
label: "execute-sql",
input: '{"query":"SELECT 1"}',
});
});
it("formats `info <tool>` with no args", () => {
expect(getPostHogExecDisplay({ command: "info execute-sql" })).toEqual({
label: "Read execute-sql",
input: undefined,
});
});
it("formats `schema <tool> <field_path>` as a dotted locator", () => {
expect(
getPostHogExecDisplay({
command: "schema query-trends series",
}),
).toEqual({
label: "Inspect query-trends.series",
input: undefined,
});
});
it("uses the regex pattern as input for search", () => {
expect(getPostHogExecDisplay({ command: "search query-" })).toEqual({
label: "Search tools",
input: "query-",
});
});
it("formats bare `tools`", () => {
expect(getPostHogExecDisplay({ command: "tools" })).toEqual({
label: "List tools",
input: undefined,
});
});
it("prefers an explicit object `input` over command-embedded args", () => {
expect(
getPostHogExecDisplay({
command: "call execute-sql",
input: { query: "SELECT 1" },
}),
).toEqual({
label: "execute-sql",
input: '{"query":"SELECT 1"}',
});
});
it("returns null for malformed input", () => {
expect(getPostHogExecDisplay(undefined)).toBeNull();
expect(getPostHogExecDisplay({})).toBeNull();
expect(getPostHogExecDisplay({ command: "call" })).toBeNull();
});
});
describe("formatPosthogExecBody", () => {
it("pretty-prints JSON object payloads", () => {
expect(formatPosthogExecBody('{"id":3}')).toBe('{\n "id": 3\n}');
});
it("returns non-JSON strings unchanged", () => {
expect(formatPosthogExecBody("query-")).toBe("query-");
});
it("returns JSON primitives unchanged", () => {
expect(formatPosthogExecBody("42")).toBe("42");
});
});