summaryrefslogtreecommitdiffhomepage
path: root/packages/core/tests/lsp/luau-lsp.smoke.test.ts
blob: 381435b9528a491efee5c4ca6974b3419c470da6 (plain)
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
import { execSync } from "node:child_process";
import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { LspManager } from "../../src/lsp/manager.js";
import { resolveServersFromConfig } from "../../src/lsp/server.js";

/**
 * Opt-in smoke test against the REAL luau-lsp binary. Skipped automatically
 * (never fails CI) when `luau-lsp` is not on PATH — mirrors opencode's
 * platform-guarded launch test. When the binary IS present, it proves the
 * end-to-end path: spawn → initialize handshake → didOpen → real diagnostics.
 */
function hasLuauLsp(): boolean {
	try {
		execSync("luau-lsp --version", { stdio: "ignore" });
		return true;
	} catch {
		return false;
	}
}

const RUN = hasLuauLsp();

describe.skipIf(!RUN)("luau-lsp real-binary smoke", () => {
	let root: string;
	let manager: LspManager;

	beforeEach(async () => {
		root = await mkdtemp(join(tmpdir(), "dispatch-luau-smoke-"));
		manager = new LspManager();
	});
	afterEach(async () => {
		await manager.shutdownAll();
		await rm(root, { recursive: true, force: true });
	});

	it("reports a real type error for a bad .luau file", async () => {
		const servers = resolveServersFromConfig({
			"luau-lsp": {
				command: ["luau-lsp", "lsp"],
				extensions: [".luau"],
				initialization: {
					"luau-lsp": {
						platform: { type: "roblox" },
						diagnostics: { strictDatamodelTypes: false },
					},
				},
			},
		});

		const file = join(root, "bad.luau");
		await writeFile(file, 'local x: number = "not a number"\nprint(x)\n');

		await manager.touchFile({ file, root, servers, mode: "document" });
		const diagnostics = manager.getDiagnostics({ root, servers, file });
		const messages = (diagnostics[file] ?? []).map((d) => d.message).join("\n");

		expect(messages.length).toBeGreaterThan(0);
		expect(messages.toLowerCase()).toContain("number");
	}, 60_000);
});