|
1 | 1 | import { mkdtemp, writeFile } from "node:fs/promises"; |
2 | 2 | import { tmpdir } from "node:os"; |
3 | 3 | import { join } from "node:path"; |
4 | | -import type { ProviderDefinition } from "@coder-studio/core"; |
| 4 | +import type { LspToolRuntimeStatusEntry, ProviderDefinition } from "@coder-studio/core"; |
5 | 5 | import { providerRegistry } from "@coder-studio/providers"; |
6 | 6 | import { describe, expect, it } from "vitest"; |
7 | 7 | import type { EventBus } from "../bus/event-bus.js"; |
@@ -57,6 +57,36 @@ function createContext(overrides: Partial<CommandContext> = {}): CommandContext |
57 | 57 | }, |
58 | 58 | ...providerRuntimeDeps, |
59 | 59 | }, |
| 60 | + lspMgr: { |
| 61 | + getRuntimeMode: () => "auto", |
| 62 | + } as never, |
| 63 | + lspToolMgr: { |
| 64 | + runtimeStatus: async ({ serverKind }: { serverKind: string }) => |
| 65 | + ({ |
| 66 | + serverKind, |
| 67 | + displayName: `${serverKind} language server`, |
| 68 | + available: serverKind === "typescript", |
| 69 | + autoInstallSupported: serverKind !== "typescript", |
| 70 | + installReadiness: |
| 71 | + serverKind === "python" |
| 72 | + ? "missing_prerequisite" |
| 73 | + : serverKind === "rust" |
| 74 | + ? "unsupported_platform" |
| 75 | + : "ready", |
| 76 | + missingCommands: |
| 77 | + serverKind === "python" |
| 78 | + ? ["pylsp"] |
| 79 | + : serverKind === "go" |
| 80 | + ? ["gopls"] |
| 81 | + : serverKind === "vue" |
| 82 | + ? ["vue-language-server"] |
| 83 | + : [], |
| 84 | + missingPrerequisites: serverKind === "python" ? ["python3"] : [], |
| 85 | + }) satisfies LspToolRuntimeStatusEntry, |
| 86 | + } as never, |
| 87 | + lspToolInstallMgr: { |
| 88 | + getLatestFailure: () => undefined, |
| 89 | + } as never, |
60 | 90 | ...restOverrides, |
61 | 91 | }; |
62 | 92 | } |
@@ -103,6 +133,37 @@ describe("diagnostics commands", () => { |
103 | 133 | }), |
104 | 134 | ]) |
105 | 135 | ); |
| 136 | + expect( |
| 137 | + ( |
| 138 | + result.data as { |
| 139 | + lspServices: Array<{ serverKind: string; status: string }>; |
| 140 | + metadata: { |
| 141 | + lspRuntimeContext?: { |
| 142 | + targetRuntime: "native" | "wsl"; |
| 143 | + managedInstallSupported: boolean; |
| 144 | + }; |
| 145 | + }; |
| 146 | + } |
| 147 | + ).lspServices |
| 148 | + ).toEqual([ |
| 149 | + expect.objectContaining({ serverKind: "typescript", status: "installed" }), |
| 150 | + expect.objectContaining({ serverKind: "python", status: "prerequisite_missing" }), |
| 151 | + expect.objectContaining({ serverKind: "go", status: "not_installed" }), |
| 152 | + expect.objectContaining({ serverKind: "rust", status: "not_installed" }), |
| 153 | + expect.objectContaining({ serverKind: "vue", status: "not_installed" }), |
| 154 | + ]); |
| 155 | + expect( |
| 156 | + ( |
| 157 | + result.data as { |
| 158 | + metadata: { |
| 159 | + lspRuntimeContext?: { |
| 160 | + targetRuntime: "native" | "wsl"; |
| 161 | + managedInstallSupported: boolean; |
| 162 | + }; |
| 163 | + }; |
| 164 | + } |
| 165 | + ).metadata.lspRuntimeContext |
| 166 | + ).toBeUndefined(); |
106 | 167 | }); |
107 | 168 |
|
108 | 169 | it("surfaces missing provider CLI checks for session start diagnostics", async () => { |
@@ -146,6 +207,119 @@ describe("diagnostics commands", () => { |
146 | 207 | ); |
147 | 208 | }); |
148 | 209 |
|
| 210 | + it("surfaces latest failed LSP install state without affecting canContinue", async () => { |
| 211 | + const workspaceDir = await mkdtemp(join(tmpdir(), "diagnostics-lsp-runtime-")); |
| 212 | + const result = await dispatch( |
| 213 | + { |
| 214 | + kind: "command", |
| 215 | + id: "diag-session-lsp-install-failed", |
| 216 | + op: "diagnostics.get", |
| 217 | + args: { |
| 218 | + context: "session_start", |
| 219 | + workspaceId: "ws-1", |
| 220 | + providerId: "claude", |
| 221 | + }, |
| 222 | + }, |
| 223 | + createContext({ |
| 224 | + workspaceMgr: { |
| 225 | + get: (workspaceId: string) => |
| 226 | + workspaceId === "ws-1" ? { id: "ws-1", path: workspaceDir } : undefined, |
| 227 | + list: () => [], |
| 228 | + } as unknown as WorkspaceManager, |
| 229 | + lspToolMgr: { |
| 230 | + runtimeStatus: async ({ serverKind }: { serverKind: string }) => |
| 231 | + ({ |
| 232 | + serverKind, |
| 233 | + displayName: `${serverKind} language server`, |
| 234 | + available: false, |
| 235 | + autoInstallSupported: true, |
| 236 | + installReadiness: "ready", |
| 237 | + missingCommands: [serverKind], |
| 238 | + missingPrerequisites: [], |
| 239 | + }) satisfies LspToolRuntimeStatusEntry, |
| 240 | + } as never, |
| 241 | + lspToolInstallMgr: { |
| 242 | + getLatestFailure: (serverKind: string) => |
| 243 | + serverKind === "go" |
| 244 | + ? { |
| 245 | + jobId: "job-go-failed", |
| 246 | + serverKind: "go", |
| 247 | + status: "failed", |
| 248 | + steps: [], |
| 249 | + failure: { |
| 250 | + code: "command_failed", |
| 251 | + serverKind: "go", |
| 252 | + message: "install failed", |
| 253 | + failedStepId: "install-go-lsp", |
| 254 | + command: "go", |
| 255 | + args: ["install"], |
| 256 | + missingCommands: [], |
| 257 | + }, |
| 258 | + } |
| 259 | + : undefined, |
| 260 | + } as never, |
| 261 | + }) |
| 262 | + ); |
| 263 | + |
| 264 | + expect(result.ok).toBe(true); |
| 265 | + expect(result.data).toMatchObject({ |
| 266 | + context: "session_start", |
| 267 | + canContinue: true, |
| 268 | + metadata: { |
| 269 | + workspaceId: "ws-1", |
| 270 | + workspacePath: workspaceDir, |
| 271 | + providerId: "claude", |
| 272 | + lspRuntimeContext: { |
| 273 | + targetRuntime: "native", |
| 274 | + managedInstallSupported: true, |
| 275 | + }, |
| 276 | + }, |
| 277 | + }); |
| 278 | + expect( |
| 279 | + (result.data as { lspServices: Array<{ serverKind: string; status: string }> }).lspServices |
| 280 | + ).toEqual( |
| 281 | + expect.arrayContaining([ |
| 282 | + expect.objectContaining({ serverKind: "go", status: "install_failed" }), |
| 283 | + ]) |
| 284 | + ); |
| 285 | + expect((result.data as { checks: Array<{ code: string }> }).checks).not.toEqual( |
| 286 | + expect.arrayContaining([expect.objectContaining({ code: "lsp_install_failed" })]) |
| 287 | + ); |
| 288 | + }); |
| 289 | + |
| 290 | + it("reports runtime_off only when the global LSP runtime mode is off", async () => { |
| 291 | + const result = await dispatch( |
| 292 | + { |
| 293 | + kind: "command", |
| 294 | + id: "diag-session-lsp-runtime-off", |
| 295 | + op: "diagnostics.get", |
| 296 | + args: { |
| 297 | + context: "session_start", |
| 298 | + workspaceId: "ws-1", |
| 299 | + providerId: "claude", |
| 300 | + }, |
| 301 | + }, |
| 302 | + createContext({ |
| 303 | + lspMgr: { |
| 304 | + getRuntimeMode: () => "off", |
| 305 | + } as never, |
| 306 | + }) |
| 307 | + ); |
| 308 | + |
| 309 | + expect(result.ok).toBe(true); |
| 310 | + expect( |
| 311 | + (result.data as { lspServices: Array<{ serverKind: string; status: string }> }).lspServices |
| 312 | + ).toEqual( |
| 313 | + expect.arrayContaining([ |
| 314 | + expect.objectContaining({ serverKind: "typescript", status: "runtime_off" }), |
| 315 | + expect.objectContaining({ serverKind: "python", status: "runtime_off" }), |
| 316 | + expect.objectContaining({ serverKind: "go", status: "runtime_off" }), |
| 317 | + expect.objectContaining({ serverKind: "rust", status: "runtime_off" }), |
| 318 | + expect.objectContaining({ serverKind: "vue", status: "runtime_off" }), |
| 319 | + ]) |
| 320 | + ); |
| 321 | + }); |
| 322 | + |
149 | 323 | it("blocks session start when node is missing but keeps workspace-open non-blocking", async () => { |
150 | 324 | const workspaceDir = await mkdtemp(join(tmpdir(), "diagnostics-base-runtime-")); |
151 | 325 | const nodeMissingContext = createContext({ |
|
0 commit comments