@nexiq/cli 1.0.1 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/cli.js +320 -0
- package/dist/devtools-3T2XQNYQ.js +5 -0
- package/package.json +25 -37
- package/src/cli.tsx +107 -0
- package/src/components/CacheApp.tsx +187 -0
- package/src/components/HelpApp.tsx +90 -0
- package/src/components/StartApp.tsx +125 -0
- package/src/components/StatusApp.tsx +116 -0
- package/src/components/StopApp.tsx +90 -0
- package/src/components/ui.tsx +128 -0
- package/src/server-process.ts +392 -0
- package/src/ws.d.ts +9 -0
- package/tsconfig.json +6 -13
- package/tsup.config.ts +45 -4
- package/dist/index.d.ts +0 -365
- package/dist/index.js +0 -2438
- package/eslint.config.js +0 -33
- package/src/index.ts +0 -32
- package/src/projectManager.test.ts +0 -897
- package/src/projectManager.ts +0 -1550
- package/src/server.test.ts +0 -782
- package/src/server.ts +0 -1710
- package/src/token-optimization.test.ts +0 -198
- package/src/tools.test.ts +0 -309
- package/vitest.config.ts +0 -36
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
import { BackendServer } from "./server.js";
|
|
3
|
-
import { ProjectManager } from "./projectManager.js";
|
|
4
|
-
import fs from "node:fs";
|
|
5
|
-
import { analyzeProject } from "@nexiq/analyser";
|
|
6
|
-
import type { JsonData } from "@nexiq/shared";
|
|
7
|
-
import Database from "better-sqlite3";
|
|
8
|
-
|
|
9
|
-
vi.mock("node:fs");
|
|
10
|
-
vi.mock("@parcel/watcher");
|
|
11
|
-
|
|
12
|
-
const createMockStmt = () => ({
|
|
13
|
-
all: vi.fn(() => []),
|
|
14
|
-
get: vi.fn(() => undefined),
|
|
15
|
-
run: vi.fn(() => ({ changes: 0 })),
|
|
16
|
-
prepare: vi.fn(() => createMockStmt()),
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const mockDb = {
|
|
20
|
-
prepare: vi.fn(() => createMockStmt() as unknown as Database.Statement),
|
|
21
|
-
close: vi.fn(),
|
|
22
|
-
exec: vi.fn(),
|
|
23
|
-
pragma: vi.fn(),
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
vi.mock("@nexiq/analyser", () => ({
|
|
27
|
-
analyzeProject: vi.fn(),
|
|
28
|
-
}));
|
|
29
|
-
|
|
30
|
-
vi.mock("@nexiq/analyser/db/sqlite", () => ({
|
|
31
|
-
SqliteDB: vi.fn().mockImplementation(() => ({
|
|
32
|
-
db: mockDb,
|
|
33
|
-
getAllData: vi.fn().mockReturnValue({
|
|
34
|
-
files: [],
|
|
35
|
-
entities: [],
|
|
36
|
-
scopes: [],
|
|
37
|
-
symbols: [],
|
|
38
|
-
renders: [],
|
|
39
|
-
exports: [],
|
|
40
|
-
relations: [],
|
|
41
|
-
}),
|
|
42
|
-
close: () => mockDb.close(),
|
|
43
|
-
})),
|
|
44
|
-
}));
|
|
45
|
-
|
|
46
|
-
vi.mock("better-sqlite3", () => {
|
|
47
|
-
return {
|
|
48
|
-
default: vi.fn(() => mockDb),
|
|
49
|
-
};
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe("Token Optimization Tools", () => {
|
|
53
|
-
let server: BackendServer;
|
|
54
|
-
let projectManager: ProjectManager;
|
|
55
|
-
const projectPath = "/test/project";
|
|
56
|
-
|
|
57
|
-
beforeEach(async () => {
|
|
58
|
-
vi.clearAllMocks();
|
|
59
|
-
mockDb.prepare.mockReset();
|
|
60
|
-
mockDb.prepare.mockImplementation(
|
|
61
|
-
() => createMockStmt() as unknown as Database.Statement,
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
65
|
-
vi.mocked(fs.readFileSync).mockReturnValue("{}");
|
|
66
|
-
|
|
67
|
-
vi.mocked(analyzeProject).mockResolvedValue({
|
|
68
|
-
src: projectPath,
|
|
69
|
-
files: {
|
|
70
|
-
"/src/App.tsx": {
|
|
71
|
-
path: "/src/App.tsx",
|
|
72
|
-
var: { "app-id": { id: "app-id", name: { type: "identifier", name: "App" }, kind: "component", type: "function", loc: { line: 1, column: 1 } } }
|
|
73
|
-
},
|
|
74
|
-
"/src/App.test.tsx": {
|
|
75
|
-
path: "/src/App.test.tsx",
|
|
76
|
-
var: {}
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
edges: [],
|
|
80
|
-
} as unknown as JsonData);
|
|
81
|
-
|
|
82
|
-
projectManager = new ProjectManager();
|
|
83
|
-
server = new BackendServer(projectManager);
|
|
84
|
-
|
|
85
|
-
await server.handleCallTool({ name: "open_project", args: { projectPath } });
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
describe("get_symbol_info with filtering", () => {
|
|
89
|
-
it("should exclude test files by default", async () => {
|
|
90
|
-
// Definition in a test file (which should be filtered out by default)
|
|
91
|
-
mockDb.prepare.mockReturnValueOnce({
|
|
92
|
-
all: vi.fn().mockReturnValue([
|
|
93
|
-
{ id: "sym-1", name: "Button", file: "/src/Button.tsx", line: 1, column: 1, kind: "component" },
|
|
94
|
-
{ id: "sym-2", name: "Button", file: "/src/Button.test.tsx", line: 1, column: 1, kind: "component" }
|
|
95
|
-
]),
|
|
96
|
-
} as any);
|
|
97
|
-
|
|
98
|
-
const result = await server.handleCallTool({ name: "get_symbol_info", args: { projectPath, query: "Button" } });
|
|
99
|
-
const data = JSON.parse(result.content[0].text);
|
|
100
|
-
|
|
101
|
-
expect(data.definitions).toHaveLength(1);
|
|
102
|
-
expect(data.definitions[0].file).toBe("/src/Button.tsx");
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it("should allow custom exclude patterns", async () => {
|
|
106
|
-
mockDb.prepare.mockReturnValueOnce({
|
|
107
|
-
all: vi.fn().mockReturnValue([
|
|
108
|
-
{ id: "sym-1", name: "Button", file: "/src/Button.tsx", line: 1, column: 1, kind: "component" },
|
|
109
|
-
{ id: "sym-2", name: "Button", file: "/src/components/Button.tsx", line: 1, column: 1, kind: "component" }
|
|
110
|
-
]),
|
|
111
|
-
} as any);
|
|
112
|
-
|
|
113
|
-
const result = await server.handleCallTool({
|
|
114
|
-
name: "get_symbol_info",
|
|
115
|
-
args: {
|
|
116
|
-
projectPath,
|
|
117
|
-
query: "Button",
|
|
118
|
-
exclude: ["**/components/**"]
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
const data = JSON.parse(result.content[0].text);
|
|
122
|
-
|
|
123
|
-
expect(data.definitions).toHaveLength(1);
|
|
124
|
-
expect(data.definitions[0].file).toBe("/src/Button.tsx");
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
describe("list_files with filtering", () => {
|
|
129
|
-
it("should exclude node_modules and tests by default", async () => {
|
|
130
|
-
const result = await server.handleCallTool({ name: "list_files", args: { projectPath } });
|
|
131
|
-
const data = JSON.parse(result.content[0].text);
|
|
132
|
-
|
|
133
|
-
expect(data.totalFiles).toBe(1);
|
|
134
|
-
expect(data.files[0].path).toBe("/src/App.tsx");
|
|
135
|
-
// App.test.tsx should be excluded
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
describe("get_symbol_usages_with_context", () => {
|
|
140
|
-
it("should return usages with source code context", async () => {
|
|
141
|
-
// 1. Definition call
|
|
142
|
-
mockDb.prepare.mockReturnValueOnce({
|
|
143
|
-
all: vi.fn().mockReturnValue([{
|
|
144
|
-
id: "btn-1", name: "Button", file: "/src/Button.tsx", line: 1, column: 1, kind: "component"
|
|
145
|
-
}]),
|
|
146
|
-
} as any);
|
|
147
|
-
|
|
148
|
-
// 2. Usages call
|
|
149
|
-
mockDb.prepare.mockReturnValueOnce({
|
|
150
|
-
all: vi.fn().mockReturnValue([{
|
|
151
|
-
tag: "Button", file: "/src/App.tsx", line: 3, column: 10, kind: "jsx", in_name: "App"
|
|
152
|
-
}]),
|
|
153
|
-
} as any);
|
|
154
|
-
|
|
155
|
-
vi.mocked(fs.readFileSync).mockReturnValue(`import { Button } from './Button';
|
|
156
|
-
export const App = () => {
|
|
157
|
-
return <Button>Click</Button>;
|
|
158
|
-
};`);
|
|
159
|
-
|
|
160
|
-
const result = await server.handleCallTool({
|
|
161
|
-
name: "get_symbol_usages_with_context",
|
|
162
|
-
args: {
|
|
163
|
-
projectPath, query: "Button", contextLines: 1
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
const data = JSON.parse(result.content[0].text);
|
|
167
|
-
|
|
168
|
-
expect(data).toHaveLength(1);
|
|
169
|
-
expect(data[0].file).toBe("/src/App.tsx");
|
|
170
|
-
expect(data[0].line).toBe(3);
|
|
171
|
-
expect(data[0].context).toHaveLength(3); // line 2, 3, 4
|
|
172
|
-
expect(data[0].context[1]).toContain("<Button>");
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
describe("get_prop_definitions", () => {
|
|
177
|
-
it("should return clean prop summary", async () => {
|
|
178
|
-
mockDb.prepare.mockReturnValueOnce({
|
|
179
|
-
all: vi.fn().mockReturnValue([{
|
|
180
|
-
id: "btn-1", name: "Button", file: "/src/Button.tsx", line: 1, column: 1, kind: "component",
|
|
181
|
-
data_json: JSON.stringify({ props: [{ name: "label", type: "string" }] })
|
|
182
|
-
}]),
|
|
183
|
-
} as any);
|
|
184
|
-
|
|
185
|
-
const result = await server.handleCallTool({
|
|
186
|
-
name: "get_prop_definitions",
|
|
187
|
-
args: {
|
|
188
|
-
projectPath, componentName: "Button"
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
const data = JSON.parse(result.content[0].text);
|
|
192
|
-
|
|
193
|
-
expect(data).toHaveLength(1);
|
|
194
|
-
expect(data[0].name).toBe("Button");
|
|
195
|
-
expect(data[0].props[0].name).toBe("label");
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
});
|
package/src/tools.test.ts
DELETED
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
import { BackendServer } from "./server.js";
|
|
3
|
-
import { ProjectManager } from "./projectManager.js";
|
|
4
|
-
import fs from "node:fs";
|
|
5
|
-
import { analyzeProject } from "@nexiq/analyser";
|
|
6
|
-
import type { JsonData } from "@nexiq/shared";
|
|
7
|
-
import Database from "better-sqlite3";
|
|
8
|
-
|
|
9
|
-
vi.mock("node:fs");
|
|
10
|
-
vi.mock("@parcel/watcher");
|
|
11
|
-
|
|
12
|
-
const createMockStmt = () => ({
|
|
13
|
-
all: vi.fn(() => []),
|
|
14
|
-
get: vi.fn(() => undefined),
|
|
15
|
-
run: vi.fn(() => ({ changes: 0 })),
|
|
16
|
-
prepare: vi.fn(() => createMockStmt()),
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const mockDb = {
|
|
20
|
-
prepare: vi.fn(() => createMockStmt() as unknown as Database.Statement),
|
|
21
|
-
close: vi.fn(),
|
|
22
|
-
exec: vi.fn(),
|
|
23
|
-
pragma: vi.fn(),
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
vi.mock("@nexiq/analyser", () => ({
|
|
27
|
-
analyzeProject: vi.fn(),
|
|
28
|
-
}));
|
|
29
|
-
|
|
30
|
-
vi.mock("@nexiq/analyser/db/sqlite", () => ({
|
|
31
|
-
SqliteDB: vi.fn().mockImplementation(() => ({
|
|
32
|
-
db: mockDb,
|
|
33
|
-
getAllData: vi.fn().mockReturnValue({
|
|
34
|
-
files: [],
|
|
35
|
-
entities: [],
|
|
36
|
-
scopes: [],
|
|
37
|
-
symbols: [],
|
|
38
|
-
renders: [],
|
|
39
|
-
exports: [],
|
|
40
|
-
relations: [],
|
|
41
|
-
}),
|
|
42
|
-
close: () => mockDb.close(),
|
|
43
|
-
})),
|
|
44
|
-
}));
|
|
45
|
-
|
|
46
|
-
vi.mock("better-sqlite3", () => {
|
|
47
|
-
return {
|
|
48
|
-
default: vi.fn(() => mockDb),
|
|
49
|
-
};
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe("MCP Tools Integration", () => {
|
|
53
|
-
let server: BackendServer;
|
|
54
|
-
let projectManager: ProjectManager;
|
|
55
|
-
const projectPath = "/test/project";
|
|
56
|
-
|
|
57
|
-
beforeEach(async () => {
|
|
58
|
-
vi.clearAllMocks();
|
|
59
|
-
mockDb.prepare.mockReset();
|
|
60
|
-
mockDb.prepare.mockImplementation(
|
|
61
|
-
() => createMockStmt() as unknown as Database.Statement,
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
65
|
-
vi.mocked(fs.readFileSync).mockReturnValue("{}");
|
|
66
|
-
|
|
67
|
-
vi.mocked(analyzeProject).mockResolvedValue({
|
|
68
|
-
src: projectPath,
|
|
69
|
-
files: {
|
|
70
|
-
"/src/App.tsx": {
|
|
71
|
-
path: "/src/App.tsx",
|
|
72
|
-
import: { "react": { localName: "React", source: "react" } },
|
|
73
|
-
var: { "app-id": { id: "app-id", name: { type: "identifier", name: "App" }, kind: "component", type: "function", loc: { line: 1, column: 1 } } }
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
edges: [],
|
|
77
|
-
} as unknown as JsonData);
|
|
78
|
-
|
|
79
|
-
projectManager = new ProjectManager();
|
|
80
|
-
server = new BackendServer(projectManager);
|
|
81
|
-
|
|
82
|
-
// Pre-open the project for most tests
|
|
83
|
-
await server.handleCallTool({ name: "open_project", args: { projectPath } });
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it("open_project: should initialize project and return success message", async () => {
|
|
87
|
-
const result = await server.handleCallTool({ name: "open_project", args: { projectPath: "/new/path" } });
|
|
88
|
-
expect(result.content[0].text).toContain("opened and analyzed successfully");
|
|
89
|
-
expect(analyzeProject).toHaveBeenCalledWith("/new/path", expect.any(String), undefined, expect.any(String));
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
describe("get_symbol_info", () => {
|
|
93
|
-
it("should return definitions only by default", async () => {
|
|
94
|
-
mockDb.prepare.mockReturnValueOnce({
|
|
95
|
-
all: vi.fn().mockReturnValue([{
|
|
96
|
-
id: "sym-1", name: "Button", file: "/src/Button.tsx", line: 10, column: 5, kind: "component", type: "function"
|
|
97
|
-
}]),
|
|
98
|
-
} as any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
99
|
-
|
|
100
|
-
const result = await server.handleCallTool({ name: "get_symbol_info", args: { projectPath, query: "Button" } });
|
|
101
|
-
const data = JSON.parse(result.content[0].text);
|
|
102
|
-
|
|
103
|
-
expect(data.definitions).toHaveLength(1);
|
|
104
|
-
expect(data.definitions[0].name).toBe("Button");
|
|
105
|
-
expect(data.definitions[0].loc).toBeUndefined(); // loc false by default
|
|
106
|
-
expect(data.usages).toBeUndefined();
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it("should include usages and location when requested", async () => {
|
|
110
|
-
// 1. Definition call
|
|
111
|
-
mockDb.prepare.mockReturnValueOnce({
|
|
112
|
-
all: vi.fn().mockReturnValue([{
|
|
113
|
-
id: "sym-1", name: "Button", file: "/src/Button.tsx", line: 10, column: 5, kind: "component", type: "function"
|
|
114
|
-
}]),
|
|
115
|
-
} as any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
116
|
-
|
|
117
|
-
// 2. Usages call
|
|
118
|
-
mockDb.prepare.mockReturnValueOnce({
|
|
119
|
-
all: vi.fn().mockReturnValue([{
|
|
120
|
-
tag: "Button", file: "/src/App.tsx", line: 20, column: 8, kind: "jsx", in_name: "App"
|
|
121
|
-
}]),
|
|
122
|
-
} as any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
123
|
-
|
|
124
|
-
const result = await server.handleCallTool({ name: "get_symbol_info", args: {
|
|
125
|
-
projectPath, query: "Button", usages: true, loc: true
|
|
126
|
-
} });
|
|
127
|
-
const data = JSON.parse(result.content[0].text);
|
|
128
|
-
|
|
129
|
-
expect(data.definitions[0].loc).toBeDefined();
|
|
130
|
-
expect(data.definitions[0].usages).toHaveLength(1);
|
|
131
|
-
expect(data.definitions[0].usages[0].file).toBe("/src/App.tsx");
|
|
132
|
-
expect(data.definitions[0].usages[0].in).toBe("App");
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it("should handle external usages fallback", async () => {
|
|
136
|
-
// 1. Definition call (empty)
|
|
137
|
-
mockDb.prepare.mockReturnValueOnce({ all: vi.fn().mockReturnValue([]) } as any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
138
|
-
// 2. External Usages call
|
|
139
|
-
mockDb.prepare.mockReturnValueOnce({
|
|
140
|
-
all: vi.fn().mockReturnValue([{
|
|
141
|
-
tag: "div", file: "/src/App.tsx", line: 5, column: 5, kind: "jsx"
|
|
142
|
-
}]),
|
|
143
|
-
} as any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
144
|
-
|
|
145
|
-
const result = await server.handleCallTool({ name: "get_symbol_info", args: {
|
|
146
|
-
projectPath, query: "div", usages: true
|
|
147
|
-
} });
|
|
148
|
-
const data = JSON.parse(result.content[0].text);
|
|
149
|
-
|
|
150
|
-
expect(data.definitions).toHaveLength(0);
|
|
151
|
-
expect(data.externalUsages).toHaveLength(1);
|
|
152
|
-
expect(data.externalUsages[0].name).toBe("div");
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("should handle non-strict matching", async () => {
|
|
156
|
-
mockDb.prepare.mockReturnValueOnce({
|
|
157
|
-
all: vi.fn().mockReturnValue([{
|
|
158
|
-
id: "sym-1", name: "Button", file: "/src/Button.tsx", line: 10, column: 5, kind: "component", type: "function"
|
|
159
|
-
}]),
|
|
160
|
-
} as any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
161
|
-
|
|
162
|
-
const result = await server.handleCallTool({ name: "get_symbol_info", args: {
|
|
163
|
-
projectPath, query: "But", strict: false
|
|
164
|
-
} });
|
|
165
|
-
const data = JSON.parse(result.content[0].text);
|
|
166
|
-
|
|
167
|
-
expect(data.definitions).toHaveLength(1);
|
|
168
|
-
expect(data.definitions[0].name).toBe("Button");
|
|
169
|
-
expect(mockDb.prepare).toHaveBeenCalledWith(expect.stringContaining("LIKE ?"));
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it("find_files: should support glob patterns", async () => {
|
|
174
|
-
const result = await server.handleCallTool({ name: "find_files", args: { projectPath, pattern: "**/*.tsx" } });
|
|
175
|
-
const files = JSON.parse(result.content[0].text);
|
|
176
|
-
expect(files).toContain("/src/App.tsx");
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it("get_file_imports: should return imports for a file", async () => {
|
|
180
|
-
const result = await server.handleCallTool({ name: "get_file_imports", args: { projectPath, filePath: "src/App.tsx" } });
|
|
181
|
-
const imports = JSON.parse(result.content[0].text);
|
|
182
|
-
expect(imports["react"]).toBeDefined();
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it("get_project_tree: should return tree up to maxDepth", async () => {
|
|
186
|
-
const result = await server.handleCallTool({ name: "get_project_tree", args: { projectPath, maxDepth: 1 } });
|
|
187
|
-
const tree = JSON.parse(result.content[0].text);
|
|
188
|
-
expect(tree.name).toBe("/");
|
|
189
|
-
expect(tree.children[0].name).toBe("src");
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it("list_files: should return summary for small projects", async () => {
|
|
193
|
-
const result = await server.handleCallTool({ name: "list_files", args: { projectPath } });
|
|
194
|
-
const data = JSON.parse(result.content[0].text);
|
|
195
|
-
expect(data.totalFiles).toBe(1);
|
|
196
|
-
expect(data.files[0].path).toBe("/src/App.tsx");
|
|
197
|
-
expect(data.files[0].exports).toBeDefined();
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it("get_component_hierarchy: should return rendered and renderedBy", async () => {
|
|
201
|
-
// 1. Start component call
|
|
202
|
-
mockDb.prepare.mockReturnValueOnce({
|
|
203
|
-
all: vi.fn().mockReturnValue([{ id: "app-id", name: "App", file: "/src/App.tsx" }]),
|
|
204
|
-
} as any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
205
|
-
// 2. renderedBy call
|
|
206
|
-
mockDb.prepare.mockReturnValueOnce({
|
|
207
|
-
all: vi.fn().mockReturnValue([{ id: "root-id", name: "Root", file: "/src/index.tsx" }]),
|
|
208
|
-
} as any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
209
|
-
// 3. sym call (App)
|
|
210
|
-
mockDb.prepare.mockReturnValueOnce({
|
|
211
|
-
get: vi.fn().mockReturnValue({ id: "app-id", name: "App" }),
|
|
212
|
-
} as any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
213
|
-
// 4. children call (App renders)
|
|
214
|
-
mockDb.prepare.mockReturnValueOnce({
|
|
215
|
-
all: vi.fn().mockReturnValue([{ tag: "Button", symbol_id: "btn-id", file: "/src/App.tsx" }]),
|
|
216
|
-
} as any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
217
|
-
// 5. sym call (Button)
|
|
218
|
-
mockDb.prepare.mockReturnValueOnce({
|
|
219
|
-
get: vi.fn().mockReturnValue({ id: "btn-id", name: "Button" }),
|
|
220
|
-
} as any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
221
|
-
// 6. children call (Button renders - empty)
|
|
222
|
-
mockDb.prepare.mockReturnValueOnce({ all: vi.fn().mockReturnValue([]) } as any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
223
|
-
|
|
224
|
-
const result = await server.handleCallTool({ name: "get_component_hierarchy", args: { projectPath, componentName: "App" } });
|
|
225
|
-
const data = JSON.parse(result.content[0].text);
|
|
226
|
-
|
|
227
|
-
expect(data.component).toBe("App");
|
|
228
|
-
expect(data.hierarchies[0].name).toBe("App");
|
|
229
|
-
expect(data.hierarchies[0].children[0].name).toBe("Button");
|
|
230
|
-
expect(data.renderedBy[0].name).toBe("Root");
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it("get_symbol_location: should return file and line", async () => {
|
|
234
|
-
mockDb.prepare.mockReturnValueOnce({
|
|
235
|
-
all: vi.fn().mockReturnValue([{
|
|
236
|
-
id: "id1", name: "App", file: "/src/App.tsx", line: 5, column: 1, kind: "component", type: "function"
|
|
237
|
-
}]),
|
|
238
|
-
} as any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
239
|
-
|
|
240
|
-
const result = await server.handleCallTool({ name: "get_symbol_location", args: { projectPath, query: "App" } });
|
|
241
|
-
const locs = JSON.parse(result.content[0].text);
|
|
242
|
-
expect(locs[0].file).toBe("/src/App.tsx");
|
|
243
|
-
expect(locs[0].loc.line).toBe(5);
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
it("get_symbol_content: should return source code line", async () => {
|
|
247
|
-
// 1. Location call
|
|
248
|
-
mockDb.prepare.mockReturnValueOnce({
|
|
249
|
-
all: vi.fn().mockReturnValue([{
|
|
250
|
-
id: "id1", name: "App", file: "/src/App.tsx", line: 2, column: 1, kind: "component", type: "function"
|
|
251
|
-
}]),
|
|
252
|
-
} as any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
253
|
-
|
|
254
|
-
vi.mocked(fs.readFileSync).mockReturnValue(`line 1
|
|
255
|
-
export const App = () => {}
|
|
256
|
-
line 3`);
|
|
257
|
-
|
|
258
|
-
const result = await server.handleCallTool({ name: "get_symbol_content", args: { projectPath, query: "App" } });
|
|
259
|
-
const contents = JSON.parse(result.content[0].text);
|
|
260
|
-
expect(contents[0].content).toBe("export const App = () => {}");
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
it("add_label / list_labels / search_by_label: should manage entity labels", async () => {
|
|
264
|
-
await server.handleCallTool({ name: "add_label", args: { projectPath, id: "app-id", label: "entry" } });
|
|
265
|
-
|
|
266
|
-
const listResult = await server.handleCallTool({ name: "list_labels", args: { projectPath } });
|
|
267
|
-
const labels = JSON.parse(listResult.content[0].text);
|
|
268
|
-
expect(labels["app-id"]).toContain("entry");
|
|
269
|
-
|
|
270
|
-
const searchResult = await server.handleCallTool({ name: "search_by_label", args: { projectPath, label: "entry" } });
|
|
271
|
-
const ids = JSON.parse(searchResult.content[0].text);
|
|
272
|
-
expect(ids).toContain("app-id");
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
it("list_directory: should return files and subdirs", async () => {
|
|
276
|
-
const result = await server.handleCallTool({ name: "list_directory", args: { projectPath, dirPath: "src" } });
|
|
277
|
-
const data = JSON.parse(result.content[0].text);
|
|
278
|
-
expect(data.files).toContain("App.tsx");
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
it("get_file_outline: should return symbols in a file", async () => {
|
|
282
|
-
const result = await server.handleCallTool({ name: "get_file_outline", args: { projectPath, filePath: "src/App.tsx" } });
|
|
283
|
-
const outline = JSON.parse(result.content[0].text);
|
|
284
|
-
expect(outline[0].name).toBe("App");
|
|
285
|
-
expect(outline[0].line).toBe(1);
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
it("read_file: should return raw file content", async () => {
|
|
289
|
-
vi.mocked(fs.readFileSync).mockReturnValue("raw content");
|
|
290
|
-
const result = await server.handleCallTool({ name: "read_file", args: { projectPath, filePath: "src/App.tsx" } });
|
|
291
|
-
expect(result.content[0].text).toBe("raw content");
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
it("grep_search: should find occurrences", async () => {
|
|
295
|
-
vi.mocked(fs.readFileSync).mockReturnValue(`const x = 1;
|
|
296
|
-
console.log(x);`);
|
|
297
|
-
const result = await server.handleCallTool({ name: "grep_search", args: { projectPath, pattern: "console" } });
|
|
298
|
-
const matches = JSON.parse(result.content[0].text);
|
|
299
|
-
expect(matches[0].file).toBe("/src/App.tsx");
|
|
300
|
-
expect(matches[0].content).toBe("console.log(x);");
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
it("run_shell_command: should execute and return output", async () => {
|
|
304
|
-
// Mocking promisified exec is a bit tricky, but projectManager uses execAsync
|
|
305
|
-
// We can mock it if needed, but let's at least test the restricted command check
|
|
306
|
-
await expect(server.handleCallTool({ name: "run_shell_command", args: { projectPath, command: "rm -rf /" } }))
|
|
307
|
-
.rejects.toThrow("restricted");
|
|
308
|
-
});
|
|
309
|
-
});
|
package/vitest.config.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "vitest/config";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
4
|
-
|
|
5
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
6
|
-
|
|
7
|
-
export default defineConfig({
|
|
8
|
-
resolve: {
|
|
9
|
-
alias: {
|
|
10
|
-
"@nexiq/shared/db": path.resolve(__dirname, "../shared/src/db/sqlite.ts"),
|
|
11
|
-
"@nexiq/shared": path.resolve(__dirname, "../shared/src/index.ts"),
|
|
12
|
-
"@nexiq/analyser/db/sqlite": path.resolve(__dirname, "../analyser/src/db/sqlite.ts"),
|
|
13
|
-
"@nexiq/analyser": path.resolve(__dirname, "../analyser/src/index.ts"),
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
test: {
|
|
17
|
-
coverage: {
|
|
18
|
-
provider: "v8",
|
|
19
|
-
reporter: ["text", "json", "html"],
|
|
20
|
-
thresholds: {
|
|
21
|
-
lines: 99,
|
|
22
|
-
functions: 100,
|
|
23
|
-
branches: 60,
|
|
24
|
-
statements: 99,
|
|
25
|
-
},
|
|
26
|
-
exclude: [
|
|
27
|
-
"node_modules",
|
|
28
|
-
"dist",
|
|
29
|
-
"src/index.ts",
|
|
30
|
-
"**/*.test.ts",
|
|
31
|
-
"eslint.config.js",
|
|
32
|
-
"vitest.config.ts",
|
|
33
|
-
],
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
});
|