migrate context foler
This commit is contained in:
parent
1bcb9b2199
commit
b6f7143882
6 changed files with 38 additions and 27 deletions
|
|
@ -1,10 +1,10 @@
|
|||
import { jest } from "@jest/globals";
|
||||
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import MCPConnection from "./MCPConnection";
|
||||
|
||||
describe("MCPConnection", () => {
|
||||
beforeEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe("constructor", () => {
|
||||
|
|
@ -131,10 +131,10 @@ describe("MCPConnection", () => {
|
|||
|
||||
it("should connect successfully", async () => {
|
||||
const conn = new MCPConnection(options);
|
||||
const mockConnect = jest
|
||||
const mockConnect = vi
|
||||
.spyOn(Client.prototype, "connect")
|
||||
.mockResolvedValue(undefined);
|
||||
const mockGetServerCapabilities = jest
|
||||
const mockGetServerCapabilities = vi
|
||||
.spyOn(Client.prototype, "getServerCapabilities")
|
||||
.mockReturnValue({
|
||||
resources: {},
|
||||
|
|
@ -142,12 +142,12 @@ describe("MCPConnection", () => {
|
|||
prompts: {},
|
||||
});
|
||||
|
||||
const mockListResources = jest
|
||||
const mockListResources = vi
|
||||
.spyOn(Client.prototype, "listResources")
|
||||
.mockResolvedValue({
|
||||
resources: [{ name: "test-resource", uri: "test-uri" }],
|
||||
});
|
||||
const mockListTools = jest
|
||||
const mockListTools = vi
|
||||
.spyOn(Client.prototype, "listTools")
|
||||
.mockResolvedValue({
|
||||
tools: [
|
||||
|
|
@ -159,7 +159,7 @@ describe("MCPConnection", () => {
|
|||
},
|
||||
],
|
||||
});
|
||||
const mockListPrompts = jest
|
||||
const mockListPrompts = vi
|
||||
.spyOn(Client.prototype, "listPrompts")
|
||||
.mockResolvedValue({ prompts: [{ name: "test-prompt" }] });
|
||||
|
||||
|
|
@ -175,7 +175,7 @@ describe("MCPConnection", () => {
|
|||
|
||||
it("should handle custom connection timeout", async () => {
|
||||
const conn = new MCPConnection({ ...options, timeout: 1500 });
|
||||
const mockConnect = jest
|
||||
const mockConnect = vi
|
||||
.spyOn(Client.prototype, "connect")
|
||||
.mockImplementation(
|
||||
() => new Promise((resolve) => setTimeout(resolve, 1000)),
|
||||
|
|
@ -190,7 +190,7 @@ describe("MCPConnection", () => {
|
|||
|
||||
it("should handle connection timeout", async () => {
|
||||
const conn = new MCPConnection({ ...options, timeout: 1 });
|
||||
const mockConnect = jest
|
||||
const mockConnect = vi
|
||||
.spyOn(Client.prototype, "connect")
|
||||
.mockImplementation(
|
||||
() => new Promise((resolve) => setTimeout(resolve, 100)),
|
||||
|
|
@ -208,7 +208,7 @@ describe("MCPConnection", () => {
|
|||
const conn = new MCPConnection(options);
|
||||
conn.status = "connected";
|
||||
|
||||
const mockConnect = jest.spyOn(Client.prototype, "connect");
|
||||
const mockConnect = vi.spyOn(Client.prototype, "connect");
|
||||
const abortController = new AbortController();
|
||||
|
||||
await conn.connectClient(false, abortController.signal);
|
||||
|
|
@ -219,7 +219,7 @@ describe("MCPConnection", () => {
|
|||
|
||||
it("should handle transport errors", async () => {
|
||||
const conn = new MCPConnection(options);
|
||||
const mockConnect = jest
|
||||
const mockConnect = vi
|
||||
.spyOn(Client.prototype, "connect")
|
||||
.mockRejectedValue(new Error("spawn test-cmd ENOENT"));
|
||||
|
||||
|
|
@ -233,7 +233,7 @@ describe("MCPConnection", () => {
|
|||
|
||||
it.skip("should include stderr output in error message when stdio command fails", async () => {
|
||||
// Clear any existing mocks to ensure we get real behavior
|
||||
jest.restoreAllMocks();
|
||||
vi.restoreAllMocks();
|
||||
|
||||
// Use a command that will definitely fail and produce stderr output
|
||||
const failingOptions = {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { MCPOptions } from "../..";
|
||||
import MCPConnection from "./MCPConnection";
|
||||
import { MCPManagerSingleton } from "./MCPManagerSingleton";
|
||||
|
|
@ -18,8 +19,8 @@ class TestMCPConnection extends MCPConnection {
|
|||
} as any;
|
||||
|
||||
this.abortController = new AbortController();
|
||||
this.connectClient = jest.fn().mockResolvedValue(undefined);
|
||||
this.getStatus = jest
|
||||
this.connectClient = vi.fn().mockResolvedValue(undefined);
|
||||
this.getStatus = vi
|
||||
.fn()
|
||||
.mockReturnValue({ status: "connected", errors: [] });
|
||||
}
|
||||
|
|
@ -54,13 +55,12 @@ describe("MCPManagerSingleton", () => {
|
|||
id: string,
|
||||
options: MCPOptions,
|
||||
): MCPConnection {
|
||||
if (!this.connections.has(id)) {
|
||||
const connection = new TestMCPConnection(options);
|
||||
this.connections.set(id, connection);
|
||||
return connection;
|
||||
} else {
|
||||
if (this.connections.has(id)) {
|
||||
return this.connections.get(id)!;
|
||||
}
|
||||
const connection = new TestMCPConnection(options);
|
||||
this.connections.set(id, connection);
|
||||
return connection;
|
||||
};
|
||||
});
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ describe("MCPManagerSingleton", () => {
|
|||
"test-id",
|
||||
testOptions,
|
||||
) as TestMCPConnection;
|
||||
const closeSpy = jest.spyOn(connection.client, "close");
|
||||
const closeSpy = vi.spyOn(connection.client, "close");
|
||||
|
||||
await manager.removeConnection("test-id");
|
||||
|
||||
|
|
@ -133,8 +133,8 @@ describe("MCPManagerSingleton", () => {
|
|||
"test-id",
|
||||
testOptions,
|
||||
) as TestMCPConnection;
|
||||
const abortSpy = jest.spyOn(connection.abortController, "abort");
|
||||
const closeSpy = jest.spyOn(connection.client, "close");
|
||||
const abortSpy = vi.spyOn(connection.abortController, "abort");
|
||||
const closeSpy = vi.spyOn(connection.client, "close");
|
||||
|
||||
// Remove it by setting empty server list
|
||||
manager.setConnections([], false);
|
||||
|
|
@ -192,7 +192,7 @@ describe("MCPManagerSingleton", () => {
|
|||
});
|
||||
|
||||
it("should call onConnectionsRefreshed if defined", async () => {
|
||||
const mockCallback = jest.fn();
|
||||
const mockCallback = vi.fn();
|
||||
manager.onConnectionsRefreshed = mockCallback;
|
||||
manager.createConnection("test-id", testOptions);
|
||||
|
||||
|
|
@ -209,7 +209,7 @@ describe("MCPManagerSingleton", () => {
|
|||
testOptions,
|
||||
) as TestMCPConnection;
|
||||
const mockStatus = { status: "connected", errors: [] };
|
||||
connection.getStatus = jest.fn().mockReturnValue(mockStatus);
|
||||
connection.getStatus = vi.fn().mockReturnValue(mockStatus);
|
||||
|
||||
const statuses = manager.getStatuses();
|
||||
expect(statuses).toHaveLength(1);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import fetch from "node-fetch";
|
||||
|
||||
import { afterAll, describe, expect, test } from "vitest";
|
||||
import { contextProviderClassFromName } from ".";
|
||||
import {
|
||||
ContextProviderExtras,
|
||||
|
|
@ -8,7 +9,7 @@ import {
|
|||
} from "../..";
|
||||
import { ConfigHandler } from "../../config/ConfigHandler";
|
||||
import { LLMLogger } from "../../llm/logger";
|
||||
import { TEST_DIR } from "../../test/testDir";
|
||||
import { setUpTestDir, tearDownTestDir, TEST_DIR } from "../../test/testDir";
|
||||
import FileSystemIde from "../../util/filesystem";
|
||||
|
||||
const CONTEXT_PROVIDERS_TO_TEST: ContextProviderWithParams[] = [
|
||||
|
|
@ -25,6 +26,7 @@ const CONTEXT_PROVIDERS_TO_TEST: ContextProviderWithParams[] = [
|
|||
async function getContextProviderExtras(
|
||||
fullInput: string,
|
||||
): Promise<ContextProviderExtras> {
|
||||
setUpTestDir();
|
||||
const ide = new FileSystemIde(TEST_DIR);
|
||||
const ideSettingsPromise = ide.getIdeSettings();
|
||||
const llmLogger = new LLMLogger();
|
||||
|
|
@ -52,6 +54,10 @@ async function getContextProviderExtras(
|
|||
}
|
||||
|
||||
describe.skip("Should successfully run all context providers", () => {
|
||||
afterAll(() => {
|
||||
tearDownTestDir();
|
||||
});
|
||||
|
||||
const extrasPromise = getContextProviderExtras("Test");
|
||||
|
||||
CONTEXT_PROVIDERS_TO_TEST.forEach((provider) => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Generated by Continue
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { Chunk } from "../../index";
|
||||
|
||||
import { deduplicateChunks } from "./util";
|
||||
|
||||
describe("deduplicateChunks", () => {
|
||||
|
|
|
|||
|
|
@ -32,5 +32,9 @@ export default {
|
|||
// modulePathIgnorePatterns: [
|
||||
// "<rootDir>/config/yaml/LocalPlatformClient.test.ts",
|
||||
// ],
|
||||
testPathIgnorePatterns: ["<rootDir>/config/", "<rootDir>/autocomplete/"],
|
||||
testPathIgnorePatterns: [
|
||||
"<rootDir>/config/",
|
||||
"<rootDir>/autocomplete/",
|
||||
"<rootDir>/context/",
|
||||
],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ export default defineConfig({
|
|||
"**/*.vitest.ts",
|
||||
"config/**/*.test.ts",
|
||||
"autocomplete/**/*.test.ts",
|
||||
"context/**/*.test.ts",
|
||||
],
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue