pi-lens 3.2.0 → 3.3.1
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 +20 -0
- package/README.md +4 -10
- package/clients/__tests__/file-time.test.js +216 -0
- package/clients/__tests__/format-service.test.js +245 -0
- package/clients/__tests__/formatters.test.js +271 -0
- package/clients/agent-behavior-client.test.js +94 -0
- package/clients/biome-client.test.js +144 -0
- package/clients/cache-manager.test.js +197 -0
- package/clients/complexity-client.test.js +234 -0
- package/clients/dependency-checker.test.js +60 -0
- package/clients/dispatch/__tests__/autofix-integration.test.js +245 -0
- package/clients/dispatch/__tests__/runner-registration.test.js +234 -0
- package/clients/dispatch/__tests__/runner-registration.test.ts +2 -2
- package/clients/dispatch/dispatcher.edge.test.js +82 -0
- package/clients/dispatch/dispatcher.format.test.js +46 -0
- package/clients/dispatch/dispatcher.inline.test.js +74 -0
- package/clients/dispatch/dispatcher.test.js +116 -0
- package/clients/dispatch/runners/architect.test.js +138 -0
- package/clients/dispatch/runners/ast-grep-napi.test.js +106 -0
- package/clients/dispatch/runners/lsp.js +42 -5
- package/clients/dispatch/runners/oxlint.test.js +230 -0
- package/clients/dispatch/runners/pyright.test.js +98 -0
- package/clients/dispatch/runners/python-slop.test.js +203 -0
- package/clients/dispatch/runners/scan_codebase.test.js +89 -0
- package/clients/dispatch/runners/shellcheck.test.js +98 -0
- package/clients/dispatch/runners/spellcheck.test.js +158 -0
- package/clients/dispatch/utils/format-utils.js +1 -6
- package/clients/dispatch/utils/format-utils.ts +1 -6
- package/clients/dogfood.test.js +201 -0
- package/clients/file-kinds.test.js +169 -0
- package/clients/formatters.js +1 -1
- package/clients/go-client.test.js +127 -0
- package/clients/jscpd-client.test.js +127 -0
- package/clients/knip-client.test.js +112 -0
- package/clients/lsp/__tests__/client.test.js +310 -0
- package/clients/lsp/__tests__/client.test.ts +1 -46
- package/clients/lsp/__tests__/config.test.js +167 -0
- package/clients/lsp/__tests__/error-recovery.test.js +213 -0
- package/clients/lsp/__tests__/integration.test.js +127 -0
- package/clients/lsp/__tests__/launch.test.js +313 -0
- package/clients/lsp/__tests__/server.test.js +259 -0
- package/clients/lsp/__tests__/service.test.js +435 -0
- package/clients/lsp/client.js +32 -44
- package/clients/lsp/client.ts +36 -45
- package/clients/lsp/launch.js +11 -6
- package/clients/lsp/launch.ts +11 -6
- package/clients/lsp/server.js +27 -2
- package/clients/metrics-client.test.js +141 -0
- package/clients/ruff-client.test.js +132 -0
- package/clients/rust-client.test.js +108 -0
- package/clients/sanitize.test.js +177 -0
- package/clients/secrets-scanner.test.js +100 -0
- package/clients/test-runner-client.test.js +192 -0
- package/clients/todo-scanner.test.js +301 -0
- package/clients/type-coverage-client.test.js +105 -0
- package/clients/typescript-client.codefix.test.js +157 -0
- package/clients/typescript-client.test.js +105 -0
- package/commands/rate.test.js +119 -0
- package/index.ts +66 -72
- package/package.json +1 -1
- package/clients/bus/bus.js +0 -191
- package/clients/bus/bus.ts +0 -251
- package/clients/bus/events.js +0 -214
- package/clients/bus/events.ts +0 -279
- package/clients/bus/index.js +0 -8
- package/clients/bus/index.ts +0 -9
- package/clients/bus/integration.js +0 -158
- package/clients/bus/integration.ts +0 -227
- package/clients/dispatch/bus-dispatcher.js +0 -178
- package/clients/dispatch/bus-dispatcher.ts +0 -258
- package/clients/services/__tests__/effect-integration.test.ts +0 -111
- package/clients/services/effect-integration.js +0 -198
- package/clients/services/effect-integration.ts +0 -276
- package/clients/services/index.js +0 -7
- package/clients/services/index.ts +0 -8
- package/clients/services/runner-service.js +0 -134
- package/clients/services/runner-service.ts +0 -225
|
@@ -29,15 +29,7 @@ vi.mock("vscode-jsonrpc/node.js", () => ({
|
|
|
29
29
|
StreamMessageWriter: vi.fn(),
|
|
30
30
|
}));
|
|
31
31
|
|
|
32
|
-
vi.mock("../../bus/events.js", () => ({
|
|
33
|
-
DiagnosticFound: {
|
|
34
|
-
publish: vi.fn(),
|
|
35
|
-
subscribe: vi.fn(() => vi.fn()), // Returns unsubscribe function
|
|
36
|
-
},
|
|
37
|
-
}));
|
|
38
|
-
|
|
39
32
|
import { createMessageConnection } from "vscode-jsonrpc/node.js";
|
|
40
|
-
import { DiagnosticFound } from "../../bus/events.js";
|
|
41
33
|
|
|
42
34
|
describe("createLSPClient", () => {
|
|
43
35
|
let mockProcess: LSPProcess;
|
|
@@ -236,42 +228,6 @@ describe("createLSPClient", () => {
|
|
|
236
228
|
);
|
|
237
229
|
});
|
|
238
230
|
|
|
239
|
-
it("should publish diagnostics to bus", async () => {
|
|
240
|
-
await createLSPClient({
|
|
241
|
-
serverId: "test-server",
|
|
242
|
-
process: mockProcess,
|
|
243
|
-
root: "/test",
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
// Get the registered handler
|
|
247
|
-
const handler = mockConnection.onNotification.mock.calls.find(
|
|
248
|
-
(call: any) => call[0] === "textDocument/publishDiagnostics",
|
|
249
|
-
)?.[1];
|
|
250
|
-
|
|
251
|
-
expect(handler).toBeDefined();
|
|
252
|
-
|
|
253
|
-
// Simulate receiving diagnostics
|
|
254
|
-
const mockDiagnostics: LSPDiagnostic[] = [
|
|
255
|
-
{
|
|
256
|
-
severity: 1,
|
|
257
|
-
message: "Type error",
|
|
258
|
-
range: {
|
|
259
|
-
start: { line: 0, character: 0 },
|
|
260
|
-
end: { line: 0, character: 5 },
|
|
261
|
-
},
|
|
262
|
-
code: "TS2345",
|
|
263
|
-
},
|
|
264
|
-
];
|
|
265
|
-
|
|
266
|
-
// Call handler directly (would be debounced in real scenario)
|
|
267
|
-
handler?.({ uri: "file:///test/file.ts", diagnostics: mockDiagnostics });
|
|
268
|
-
|
|
269
|
-
// Advance past debounce (150ms)
|
|
270
|
-
await vi.advanceTimersByTimeAsync(200);
|
|
271
|
-
|
|
272
|
-
expect(DiagnosticFound.publish).toHaveBeenCalled();
|
|
273
|
-
});
|
|
274
|
-
|
|
275
231
|
it.skip("should store diagnostics for retrieval", async () => {
|
|
276
232
|
const client = await createLSPClient({
|
|
277
233
|
serverId: "test-server",
|
|
@@ -320,8 +276,7 @@ describe("createLSPClient", () => {
|
|
|
320
276
|
root: "/test",
|
|
321
277
|
});
|
|
322
278
|
|
|
323
|
-
// waitForDiagnostics
|
|
324
|
-
// With fake timers, we need to advance time to trigger the timeout
|
|
279
|
+
// waitForDiagnostics resolves via timeout when no notification arrives
|
|
325
280
|
const promise = client.waitForDiagnostics("/test/file.ts", 100);
|
|
326
281
|
await vi.advanceTimersByTimeAsync(150);
|
|
327
282
|
await promise;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LSP Configuration Test Suite
|
|
3
|
+
*
|
|
4
|
+
* Tests for configuration including:
|
|
5
|
+
* - Config file loading
|
|
6
|
+
* - Custom server creation
|
|
7
|
+
* - Server registry management
|
|
8
|
+
* - Disabled server handling
|
|
9
|
+
*/
|
|
10
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
11
|
+
// Mock fs/promises before any imports that use it
|
|
12
|
+
const mockReadFile = vi.fn();
|
|
13
|
+
const mockAccess = vi.fn();
|
|
14
|
+
const mockStat = vi.fn();
|
|
15
|
+
vi.mock("node:fs/promises", async () => {
|
|
16
|
+
return {
|
|
17
|
+
readFile: mockReadFile,
|
|
18
|
+
access: mockAccess,
|
|
19
|
+
stat: mockStat,
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
// Import after mocking - mocks are already defined above
|
|
23
|
+
const { loadLSPConfig, createCustomServer, initLSPConfig, getAllServers, isServerDisabled, getServersForFileWithConfig, } = await import("../config.js");
|
|
24
|
+
describe("loadLSPConfig", () => {
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
vi.clearAllMocks();
|
|
27
|
+
});
|
|
28
|
+
it.skip("should load config from .pi-lens/lsp.json", async () => {
|
|
29
|
+
const config = {
|
|
30
|
+
servers: {
|
|
31
|
+
"my-server": {
|
|
32
|
+
name: "My Custom Server",
|
|
33
|
+
extensions: [".myext"],
|
|
34
|
+
command: "my-lsp",
|
|
35
|
+
args: ["--stdio"],
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
mockReadFile.mockResolvedValue(JSON.stringify(config));
|
|
40
|
+
const result = await loadLSPConfig("/project");
|
|
41
|
+
expect(result).toEqual(config);
|
|
42
|
+
expect(mockReadFile).toHaveBeenCalled();
|
|
43
|
+
});
|
|
44
|
+
it("should return empty config when file not found", async () => {
|
|
45
|
+
mockReadFile.mockRejectedValue(new Error("ENOENT"));
|
|
46
|
+
const result = await loadLSPConfig("/project");
|
|
47
|
+
expect(result).toEqual({});
|
|
48
|
+
});
|
|
49
|
+
it("should handle invalid JSON gracefully", async () => {
|
|
50
|
+
mockReadFile.mockResolvedValue("not valid json");
|
|
51
|
+
const result = await loadLSPConfig("/project");
|
|
52
|
+
expect(result).toEqual({});
|
|
53
|
+
});
|
|
54
|
+
it.skip("should try multiple config paths", async () => {
|
|
55
|
+
mockReadFile
|
|
56
|
+
.mockRejectedValueOnce(new Error("ENOENT"))
|
|
57
|
+
.mockRejectedValueOnce(new Error("ENOENT"))
|
|
58
|
+
.mockResolvedValueOnce(JSON.stringify({ servers: {} }));
|
|
59
|
+
const result = await loadLSPConfig("/project");
|
|
60
|
+
expect(mockReadFile).toHaveBeenCalledTimes(3);
|
|
61
|
+
expect(result).toEqual({ servers: {} });
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
describe("createCustomServer", () => {
|
|
65
|
+
it("should create server from config", () => {
|
|
66
|
+
const config = {
|
|
67
|
+
name: "Custom LSP",
|
|
68
|
+
extensions: [".custom"],
|
|
69
|
+
command: "custom-lsp",
|
|
70
|
+
args: ["--stdio", "--verbose"],
|
|
71
|
+
rootMarkers: [".customrc"],
|
|
72
|
+
};
|
|
73
|
+
const server = createCustomServer(config, "custom-server");
|
|
74
|
+
expect(server.id).toBe("custom-server");
|
|
75
|
+
expect(server.name).toBe("Custom LSP");
|
|
76
|
+
expect(server.extensions).toEqual([".custom"]);
|
|
77
|
+
expect(typeof server.spawn).toBe("function");
|
|
78
|
+
expect(typeof server.root).toBe("function");
|
|
79
|
+
});
|
|
80
|
+
it("should use process.cwd() as root when no markers specified", async () => {
|
|
81
|
+
const config = {
|
|
82
|
+
name: "Simple LSP",
|
|
83
|
+
extensions: [".simple"],
|
|
84
|
+
command: "simple-lsp",
|
|
85
|
+
};
|
|
86
|
+
const server = createCustomServer(config, "simple");
|
|
87
|
+
const root = await server.root("/any/path/file.simple");
|
|
88
|
+
expect(root).toBe(process.cwd());
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
describe("initLSPConfig", () => {
|
|
92
|
+
beforeEach(() => {
|
|
93
|
+
vi.clearAllMocks();
|
|
94
|
+
// Reset by calling init with empty config
|
|
95
|
+
mockReadFile.mockRejectedValue(new Error("ENOENT"));
|
|
96
|
+
return initLSPConfig("/test-reset");
|
|
97
|
+
});
|
|
98
|
+
it("should initialize with empty config", async () => {
|
|
99
|
+
mockReadFile.mockRejectedValue(new Error("ENOENT"));
|
|
100
|
+
await initLSPConfig("/project");
|
|
101
|
+
const servers = getAllServers();
|
|
102
|
+
// Should have built-in servers
|
|
103
|
+
expect(servers.some((s) => s.id === "typescript")).toBe(true);
|
|
104
|
+
});
|
|
105
|
+
it.skip("should register custom servers from config", async () => {
|
|
106
|
+
const config = {
|
|
107
|
+
servers: {
|
|
108
|
+
"custom-test-server": {
|
|
109
|
+
name: "Custom Test Server",
|
|
110
|
+
extensions: [".ctest"],
|
|
111
|
+
command: "ctest-lsp",
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
mockReadFile.mockResolvedValue(JSON.stringify(config));
|
|
116
|
+
await initLSPConfig("/project");
|
|
117
|
+
const servers = getAllServers();
|
|
118
|
+
expect(servers.some((s) => s.id === "custom-test-server")).toBe(true);
|
|
119
|
+
});
|
|
120
|
+
it.skip("should handle disabled servers", async () => {
|
|
121
|
+
const config = {
|
|
122
|
+
disabledServers: ["python"],
|
|
123
|
+
};
|
|
124
|
+
mockReadFile.mockResolvedValue(JSON.stringify(config));
|
|
125
|
+
await initLSPConfig("/project");
|
|
126
|
+
expect(isServerDisabled("python")).toBe(true);
|
|
127
|
+
expect(isServerDisabled("typescript")).toBe(false);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
describe("getAllServers", () => {
|
|
131
|
+
beforeEach(async () => {
|
|
132
|
+
vi.clearAllMocks();
|
|
133
|
+
mockReadFile.mockRejectedValue(new Error("ENOENT"));
|
|
134
|
+
await initLSPConfig("/test");
|
|
135
|
+
});
|
|
136
|
+
it("should include built-in servers", () => {
|
|
137
|
+
const servers = getAllServers();
|
|
138
|
+
expect(servers.some((s) => s.id === "typescript")).toBe(true);
|
|
139
|
+
expect(servers.some((s) => s.id === "python")).toBe(true);
|
|
140
|
+
expect(servers.some((s) => s.id === "go")).toBe(true);
|
|
141
|
+
expect(servers.some((s) => s.id === "rust")).toBe(true);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
describe("getServersForFileWithConfig", () => {
|
|
145
|
+
beforeEach(async () => {
|
|
146
|
+
vi.clearAllMocks();
|
|
147
|
+
mockReadFile.mockRejectedValue(new Error("ENOENT"));
|
|
148
|
+
await initLSPConfig("/test");
|
|
149
|
+
});
|
|
150
|
+
it("should find TypeScript server for .ts files", () => {
|
|
151
|
+
const servers = getServersForFileWithConfig("/project/file.ts");
|
|
152
|
+
expect(servers.some((s) => s.id === "typescript")).toBe(true);
|
|
153
|
+
});
|
|
154
|
+
it("should find Python server for .py files", () => {
|
|
155
|
+
const servers = getServersForFileWithConfig("/project/file.py");
|
|
156
|
+
expect(servers.some((s) => s.id === "python")).toBe(true);
|
|
157
|
+
});
|
|
158
|
+
it("should return empty array for unknown file type", () => {
|
|
159
|
+
const servers = getServersForFileWithConfig("/project/file.unknown");
|
|
160
|
+
expect(servers).toEqual([]);
|
|
161
|
+
});
|
|
162
|
+
it("should be case insensitive for extensions", () => {
|
|
163
|
+
const servers1 = getServersForFileWithConfig("/project/file.TS");
|
|
164
|
+
const servers2 = getServersForFileWithConfig("/project/file.ts");
|
|
165
|
+
expect(servers1.map((s) => s.id)).toEqual(servers2.map((s) => s.id));
|
|
166
|
+
});
|
|
167
|
+
});
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LSP Error Recovery Tests
|
|
3
|
+
*
|
|
4
|
+
* Tests for LSP failure scenarios and recovery mechanisms.
|
|
5
|
+
* Critical for stability in real-world usage.
|
|
6
|
+
*/
|
|
7
|
+
import { Effect } from "effect";
|
|
8
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
9
|
+
import { getLSPService, resetLSPService } from "../index.js";
|
|
10
|
+
// Check if we should run real LSP tests
|
|
11
|
+
const runRealLSPTests = process.env.RUN_REAL_LSP_TESTS === "true";
|
|
12
|
+
describe("LSP Error Recovery", () => {
|
|
13
|
+
let service;
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
resetLSPService();
|
|
16
|
+
service = getLSPService();
|
|
17
|
+
});
|
|
18
|
+
afterEach(async () => {
|
|
19
|
+
await service.shutdown();
|
|
20
|
+
resetLSPService();
|
|
21
|
+
});
|
|
22
|
+
describe("Spawn Failures", () => {
|
|
23
|
+
it("should handle LSP spawn failure gracefully", async () => {
|
|
24
|
+
// Simulate spawn failure by using invalid command
|
|
25
|
+
const result = await service.hasLSP("/test/invalid-file.xyz");
|
|
26
|
+
// Should return false without throwing
|
|
27
|
+
expect(result).toBe(false);
|
|
28
|
+
});
|
|
29
|
+
it("should handle missing LSP server binary", async () => {
|
|
30
|
+
// Test with a file type that has no installed LSP
|
|
31
|
+
const result = await service.hasLSP("/test/file.unknown");
|
|
32
|
+
expect(result).toBe(false);
|
|
33
|
+
});
|
|
34
|
+
it("should handle permission denied on spawn", async () => {
|
|
35
|
+
// This would require mocking at a lower level
|
|
36
|
+
// For now, just verify it doesn't crash
|
|
37
|
+
await expect(service.openFile("/test.ts", "content")).resolves.not.toThrow();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
describe("Runtime Crashes", () => {
|
|
41
|
+
it("should handle LSP crash during operation", async () => {
|
|
42
|
+
// Open a file first
|
|
43
|
+
await service.openFile("/test.ts", "const x = 1;");
|
|
44
|
+
// Simulate crash by shutting down abruptly
|
|
45
|
+
await service.shutdown();
|
|
46
|
+
// Subsequent operations should handle gracefully
|
|
47
|
+
const diags = await service.getDiagnostics("/test.ts");
|
|
48
|
+
expect(diags).toEqual([]);
|
|
49
|
+
});
|
|
50
|
+
it("should handle multiple rapid shutdown calls", async () => {
|
|
51
|
+
// First shutdown
|
|
52
|
+
await expect(service.shutdown()).resolves.not.toThrow();
|
|
53
|
+
// Second shutdown should also not throw
|
|
54
|
+
await expect(service.shutdown()).resolves.not.toThrow();
|
|
55
|
+
// Third shutdown
|
|
56
|
+
await expect(service.shutdown()).resolves.not.toThrow();
|
|
57
|
+
});
|
|
58
|
+
it("should handle getDiagnostics on crashed server", async () => {
|
|
59
|
+
// Get diagnostics without opening (simulates crash state)
|
|
60
|
+
const diags = await service.getDiagnostics("/nonexistent/crashed.ts");
|
|
61
|
+
expect(diags).toEqual([]);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
describe("Root Detection Edge Cases", () => {
|
|
65
|
+
it("should exclude .pi-lens from root detection", async () => {
|
|
66
|
+
// This was a real bug where .pi-lens/tools/package.json was found as root
|
|
67
|
+
// We verify the config excludes .pi-lens
|
|
68
|
+
const { getAllServers } = await import("../config.js");
|
|
69
|
+
const servers = getAllServers();
|
|
70
|
+
// Should return array (verification that config loads)
|
|
71
|
+
expect(Array.isArray(servers)).toBe(true);
|
|
72
|
+
});
|
|
73
|
+
it("should handle deeply nested file paths", async () => {
|
|
74
|
+
const deepPath = "/very/deep/nested/path/to/the/file.ts";
|
|
75
|
+
// Should not throw on deep paths
|
|
76
|
+
await expect(service.openFile(deepPath, "content")).resolves.not.toThrow();
|
|
77
|
+
await expect(service.getDiagnostics(deepPath)).resolves.not.toThrow();
|
|
78
|
+
});
|
|
79
|
+
it("should handle paths with special characters", async () => {
|
|
80
|
+
const specialPaths = [
|
|
81
|
+
"/path with spaces/file.ts",
|
|
82
|
+
"/path-with-dashes/file.ts",
|
|
83
|
+
"/path_with_underscores/file.ts",
|
|
84
|
+
"/path.with.dots/file.ts",
|
|
85
|
+
];
|
|
86
|
+
for (const path of specialPaths) {
|
|
87
|
+
await expect(service.openFile(path, "content")).resolves.not.toThrow();
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
describe("Timeout Handling", () => {
|
|
92
|
+
it("should handle slow LSP operations", async () => {
|
|
93
|
+
// Create a mock slow operation
|
|
94
|
+
const slowPromise = new Promise((resolve) => {
|
|
95
|
+
setTimeout(() => resolve("done"), 5000);
|
|
96
|
+
});
|
|
97
|
+
// Should not hang indefinitely
|
|
98
|
+
const timeoutPromise = Promise.race([
|
|
99
|
+
slowPromise,
|
|
100
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("Timeout")), 100)),
|
|
101
|
+
]);
|
|
102
|
+
await expect(timeoutPromise).rejects.toThrow("Timeout");
|
|
103
|
+
});
|
|
104
|
+
it("should handle hanging getDiagnostics", async () => {
|
|
105
|
+
// Start diagnostics request
|
|
106
|
+
const diagPromise = service.getDiagnostics("/test.ts");
|
|
107
|
+
// Should complete (even if empty) within reasonable time
|
|
108
|
+
const result = await Promise.race([
|
|
109
|
+
diagPromise,
|
|
110
|
+
new Promise((resolve) => setTimeout(() => resolve("timeout"), 1000)),
|
|
111
|
+
]);
|
|
112
|
+
// Either completes or times out gracefully
|
|
113
|
+
expect(result).toBeDefined();
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
describe("Multiple LSP Coordination", () => {
|
|
117
|
+
it("should handle multiple LSPs running simultaneously", async () => {
|
|
118
|
+
// This tests that multiple LSP servers don't interfere
|
|
119
|
+
const files = [
|
|
120
|
+
{ path: "/test.ts", content: "const x: number = 1;" },
|
|
121
|
+
{ path: "/test.py", content: "x = 1" },
|
|
122
|
+
{ path: "/test.rs", content: "let x = 1;" },
|
|
123
|
+
];
|
|
124
|
+
// Open multiple files
|
|
125
|
+
for (const file of files) {
|
|
126
|
+
await expect(service.openFile(file.path, file.content)).resolves.not.toThrow();
|
|
127
|
+
}
|
|
128
|
+
// Get diagnostics for all
|
|
129
|
+
for (const file of files) {
|
|
130
|
+
const diags = await service.getDiagnostics(file.path);
|
|
131
|
+
expect(Array.isArray(diags)).toBe(true);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
it("should handle rapid file switching", async () => {
|
|
135
|
+
const files = ["/a.ts", "/b.ts", "/c.ts"];
|
|
136
|
+
// Rapidly switch between files
|
|
137
|
+
for (let i = 0; i < 10; i++) {
|
|
138
|
+
const file = files[i % files.length];
|
|
139
|
+
await service.openFile(file, `content ${i}`);
|
|
140
|
+
await service.getDiagnostics(file);
|
|
141
|
+
}
|
|
142
|
+
// Should not crash or hang
|
|
143
|
+
expect(true).toBe(true);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
describe("Effect Integration Error Handling", () => {
|
|
147
|
+
it("should handle errors in Effect context", async () => {
|
|
148
|
+
const { lspEffect } = await import("../index.js");
|
|
149
|
+
// Try to get LSP for non-existent file type
|
|
150
|
+
const { hasLSP } = lspEffect(service);
|
|
151
|
+
const program = hasLSP("/test.unknownxyz");
|
|
152
|
+
// Should complete without throwing
|
|
153
|
+
const result = await Effect.runPromise(program);
|
|
154
|
+
expect(typeof result).toBe("boolean");
|
|
155
|
+
});
|
|
156
|
+
it("should recover from Effect failures", async () => {
|
|
157
|
+
const { lspEffect } = await import("../index.js");
|
|
158
|
+
// Shutdown then try operations
|
|
159
|
+
await service.shutdown();
|
|
160
|
+
const { shutdown } = lspEffect(service);
|
|
161
|
+
const program = shutdown();
|
|
162
|
+
// Should not throw even after shutdown
|
|
163
|
+
await expect(Effect.runPromise(program)).resolves.not.toThrow();
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
// Real server tests - these require actual LSP servers
|
|
168
|
+
// These catch real-world issues like the ESLintServer spawn error
|
|
169
|
+
describe.skipIf(!runRealLSPTests)("Real Server Error Recovery", () => {
|
|
170
|
+
let service;
|
|
171
|
+
beforeEach(() => {
|
|
172
|
+
resetLSPService();
|
|
173
|
+
service = getLSPService();
|
|
174
|
+
});
|
|
175
|
+
afterEach(async () => {
|
|
176
|
+
await service.shutdown();
|
|
177
|
+
resetLSPService();
|
|
178
|
+
});
|
|
179
|
+
it("should handle real TypeScript LSP spawn", async () => {
|
|
180
|
+
const hasTsLsp = await service.hasLSP("/test.ts");
|
|
181
|
+
if (hasTsLsp) {
|
|
182
|
+
// If installed, should be able to open and diagnose
|
|
183
|
+
await service.openFile("/test.ts", "const x: string = 1;");
|
|
184
|
+
const diags = await service.getDiagnostics("/test.ts");
|
|
185
|
+
// Should get type error
|
|
186
|
+
expect(diags.length).toBeGreaterThan(0);
|
|
187
|
+
expect(diags[0].message).toContain("Type");
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
it("should handle real Python LSP spawn", async () => {
|
|
191
|
+
const hasPyLsp = await service.hasLSP("/test.py");
|
|
192
|
+
if (hasPyLsp) {
|
|
193
|
+
await service.openFile("/test.py", "x = 1\nprint(y)"); // y is undefined
|
|
194
|
+
const diags = await service.getDiagnostics("/test.py");
|
|
195
|
+
// Should have errors about undefined y
|
|
196
|
+
expect(diags.length).toBeGreaterThan(0);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
it("should restart crashed LSP server", async () => {
|
|
200
|
+
const hasTsLsp = await service.hasLSP("/test.ts");
|
|
201
|
+
if (hasTsLsp) {
|
|
202
|
+
// Open file
|
|
203
|
+
await service.openFile("/test.ts", "const x = 1;");
|
|
204
|
+
// Get diagnostics (server should be running)
|
|
205
|
+
const _diags1 = await service.getDiagnostics("/test.ts");
|
|
206
|
+
// Shutdown (simulates crash)
|
|
207
|
+
await service.shutdown();
|
|
208
|
+
// Try to use again - should handle gracefully
|
|
209
|
+
const diags2 = await service.getDiagnostics("/test.ts");
|
|
210
|
+
expect(Array.isArray(diags2)).toBe(true);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
});
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LSP Integration Test Suite
|
|
3
|
+
*
|
|
4
|
+
* End-to-end tests for the LSP system including:
|
|
5
|
+
* - Full workflow: detect -> spawn -> open -> diagnose -> shutdown
|
|
6
|
+
* - Multiple server coordination
|
|
7
|
+
* - Error recovery scenarios
|
|
8
|
+
* - Real TypeScript server integration (optional)
|
|
9
|
+
*/
|
|
10
|
+
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
11
|
+
import { getLSPService, resetLSPService } from "../index.js";
|
|
12
|
+
import { Effect } from "effect";
|
|
13
|
+
// Check if we should run real LSP tests
|
|
14
|
+
const runRealLSPTests = process.env.RUN_REAL_LSP_TESTS === "true";
|
|
15
|
+
describe("LSP Integration", () => {
|
|
16
|
+
let service;
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
resetLSPService();
|
|
19
|
+
service = getLSPService();
|
|
20
|
+
});
|
|
21
|
+
afterEach(async () => {
|
|
22
|
+
await service.shutdown();
|
|
23
|
+
resetLSPService();
|
|
24
|
+
});
|
|
25
|
+
describe("Service Lifecycle", () => {
|
|
26
|
+
it("should handle complete lifecycle without errors", async () => {
|
|
27
|
+
// This is a basic smoke test
|
|
28
|
+
const hasLSP = await service.hasLSP("/test.ts");
|
|
29
|
+
// Result depends on whether TypeScript LSP is installed
|
|
30
|
+
// Just verify it doesn't throw
|
|
31
|
+
expect(typeof hasLSP).toBe("boolean");
|
|
32
|
+
});
|
|
33
|
+
it("should handle multiple shutdown calls gracefully", async () => {
|
|
34
|
+
// First shutdown
|
|
35
|
+
await expect(service.shutdown()).resolves.not.toThrow();
|
|
36
|
+
// Second shutdown should also not throw
|
|
37
|
+
await expect(service.shutdown()).resolves.not.toThrow();
|
|
38
|
+
});
|
|
39
|
+
it("should report status correctly", async () => {
|
|
40
|
+
const status = service.getStatus();
|
|
41
|
+
// Should return array (may be empty if no clients active)
|
|
42
|
+
expect(Array.isArray(status)).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
describe("Effect Integration", () => {
|
|
46
|
+
it("should run hasLSP effect successfully", async () => {
|
|
47
|
+
const { hasLSP } = await import("../index.js").then((m) => m.lspEffect(service));
|
|
48
|
+
const program = hasLSP("/test.ts");
|
|
49
|
+
const result = await Effect.runPromise(program);
|
|
50
|
+
expect(typeof result).toBe("boolean");
|
|
51
|
+
});
|
|
52
|
+
it("should run shutdown effect successfully", async () => {
|
|
53
|
+
const { shutdown } = await import("../index.js").then((m) => m.lspEffect(service));
|
|
54
|
+
const program = shutdown();
|
|
55
|
+
const result = await Effect.runPromise(program);
|
|
56
|
+
expect(result).toBeUndefined();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
describe("Error Handling", () => {
|
|
60
|
+
it("should handle operations on non-existent files", async () => {
|
|
61
|
+
await expect(service.openFile("/nonexistent/file.ts", "content"))
|
|
62
|
+
.resolves.not.toThrow();
|
|
63
|
+
});
|
|
64
|
+
it("should handle getDiagnostics on non-existent files", async () => {
|
|
65
|
+
const diags = await service.getDiagnostics("/nonexistent/file.ts");
|
|
66
|
+
expect(diags).toEqual([]);
|
|
67
|
+
});
|
|
68
|
+
it("should handle updateFile on non-existent files", async () => {
|
|
69
|
+
await expect(service.updateFile("/nonexistent/file.ts", "new content"))
|
|
70
|
+
.resolves.not.toThrow();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
// Real server tests - these require actual LSP servers to be installed
|
|
75
|
+
// Run with: RUN_REAL_LSP_TESTS=true npm test
|
|
76
|
+
describe.skipIf(!runRealLSPTests)("Real Server Tests", () => {
|
|
77
|
+
let service;
|
|
78
|
+
beforeEach(() => {
|
|
79
|
+
resetLSPService();
|
|
80
|
+
service = getLSPService();
|
|
81
|
+
});
|
|
82
|
+
afterEach(async () => {
|
|
83
|
+
await service.shutdown();
|
|
84
|
+
resetLSPService();
|
|
85
|
+
});
|
|
86
|
+
it("should detect TypeScript LSP if available", async () => {
|
|
87
|
+
const hasLSP = await service.hasLSP(process.cwd() + "/test.ts");
|
|
88
|
+
if (hasLSP) {
|
|
89
|
+
console.log("✅ TypeScript LSP detected");
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
console.log("⚠️ TypeScript LSP not available");
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
describe("Concurrent Operations", () => {
|
|
97
|
+
let service;
|
|
98
|
+
beforeEach(() => {
|
|
99
|
+
resetLSPService();
|
|
100
|
+
service = getLSPService();
|
|
101
|
+
});
|
|
102
|
+
afterEach(async () => {
|
|
103
|
+
await service.shutdown();
|
|
104
|
+
resetLSPService();
|
|
105
|
+
});
|
|
106
|
+
it("should handle concurrent hasLSP checks", async () => {
|
|
107
|
+
const checks = [
|
|
108
|
+
service.hasLSP("/file1.ts"),
|
|
109
|
+
service.hasLSP("/file2.ts"),
|
|
110
|
+
service.hasLSP("/file3.ts"),
|
|
111
|
+
];
|
|
112
|
+
const results = await Promise.all(checks);
|
|
113
|
+
expect(results).toHaveLength(3);
|
|
114
|
+
results.forEach((r) => expect(typeof r).toBe("boolean"));
|
|
115
|
+
});
|
|
116
|
+
it("should handle concurrent diagnostics requests", async () => {
|
|
117
|
+
// These should not throw even if files don't exist
|
|
118
|
+
const requests = [
|
|
119
|
+
service.getDiagnostics("/file1.ts"),
|
|
120
|
+
service.getDiagnostics("/file2.ts"),
|
|
121
|
+
service.getDiagnostics("/file3.ts"),
|
|
122
|
+
];
|
|
123
|
+
const results = await Promise.all(requests);
|
|
124
|
+
expect(results).toHaveLength(3);
|
|
125
|
+
results.forEach((r) => expect(Array.isArray(r)).toBe(true));
|
|
126
|
+
});
|
|
127
|
+
});
|