CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
NativeLspClient.test.ts107 linesDownload Raw Back to lsp
1/**2 * @license3 * Copyright 2025 Qwen Team4 * SPDX-License-Identifier: Apache-2.05 */6 7import { describe, expect, it, vi } from 'vitest';8import { NativeLspClient } from './NativeLspClient.js';9import type { NativeLspService } from './NativeLspService.js';10import type { LspServerHandle } from './types.js';11 12const createHandle = (overrides: Partial<LspServerHandle>): LspServerHandle =>13  ({14    config: {15      name: 'clangd',16      languages: ['cpp'],17      command: 'clangd',18      args: [],19      transport: 'stdio',20      rootUri: 'file:///workspace',21      workspaceFolder: '/workspace',22    },23    status: 'READY',24    ...overrides,25  }) as LspServerHandle;26 27describe('NativeLspClient', () => {28  it('returns status details from the current server handles', () => {29    const service = {30      getStatus: vi.fn().mockReturnValue(31        new Map([32          ['clangd', 'FAILED'],33          ['stale-server', 'READY'],34        ]),35      ),36      getServerHandles: vi.fn().mockReturnValue(37        new Map([38          [39            'clangd',40            createHandle({41              status: 'READY',42              config: {43                name: 'clangd',44                languages: ['c', 'cpp'],45                command: 'clangd',46                args: ['--background-index'],47                transport: 'stdio',48                rootUri: 'file:///workspace',49                workspaceFolder: '/workspace',50              },51            }),52          ],53        ]),54      ),55    } as unknown as NativeLspService;56 57    const client = new NativeLspClient(service);58 59    expect(client.getServerStatus()).toEqual([60      {61        name: 'clangd',62        status: 'READY',63        command: 'clangd',64        languages: ['c', 'cpp'],65      },66    ]);67    expect(service.getStatus).not.toHaveBeenCalled();68  });69 70  it('stringifies non-Error startup failures', () => {71    const service = {72      getServerHandles: vi.fn().mockReturnValue(73        new Map([74          [75            'pyright',76            createHandle({77              status: 'FAILED',78              config: {79                name: 'pyright',80                languages: ['python'],81                command: 'pyright-langserver',82                args: ['--stdio'],83                transport: 'stdio',84                rootUri: 'file:///workspace',85                workspaceFolder: '/workspace',86              },87              error: 'startup failed' as unknown as Error,88            }),89          ],90        ]),91      ),92    } as unknown as NativeLspService;93 94    const client = new NativeLspClient(service);95 96    expect(client.getServerStatus()).toEqual([97      {98        name: 'pyright',99        status: 'FAILED',100        command: 'pyright-langserver',101        languages: ['python'],102        error: 'startup failed',103      },104    ]);105  });106});107 
basant307/AI_Governance_Project · CoolFace