From 2f0a71143ba789d24159937f1d54fdcfa7e74cfe Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 12 Dec 2024 14:09:03 +0000 Subject: [PATCH 1/3] fix: use 'env' instead of 'envVars' in Claude desktop config - Updates MCPServer interface to use 'env' key - Adds unit tests to verify config structure Fixes #48 Co-Authored-By: Michael Latman --- jest.config.mjs | 1 - package-lock.json | 6 ++-- package.json | 3 +- src/utils/__tests__/config-manager.test.ts | 42 ++++++++++++++++++++++ src/utils/config-manager.ts | 10 +++--- 5 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 src/utils/__tests__/config-manager.test.ts diff --git a/jest.config.mjs b/jest.config.mjs index 1e0a812..147030c 100644 --- a/jest.config.mjs +++ b/jest.config.mjs @@ -16,7 +16,6 @@ const config = { }, testMatch: ['**/__tests__/**/*.test.ts'], testPathIgnorePatterns: ['/node_modules/', '/loaders/'], - setupFilesAfterEnv: ['/test/setup.ts'], }; export default config; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index dcee6ea..c0056df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,7 +29,7 @@ "@types/inquirer": "^8.2.4", "@types/inquirer-autocomplete-prompt": "^3.0.3", "@types/jest": "^29.5.14", - "@types/node": "^14.0.0", + "@types/node": "^14.18.63", "jest": "^29.7.0", "ts-jest": "^29.2.5", "ts-node": "^10.9.1" @@ -1223,6 +1223,7 @@ "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.14.tgz", "integrity": "sha512-ZN+4sdnLUbo8EVvVc2ao0GFW6oVrQRPn4K2lglySj7APvSrgzxHiNNK99us4WDMi57xxA2yggblIAMNhXOotLQ==", "dev": true, + "license": "MIT", "dependencies": { "expect": "^29.0.0", "pretty-format": "^29.0.0" @@ -1231,7 +1232,8 @@ "node_modules/@types/node": { "version": "14.18.63", "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.63.tgz", - "integrity": "sha512-fAtCfv4jJg+ExtXhvCkCqUKZ+4ok/JQk01qDKhL5BDDoS3AxKXhV5/MAVUZyQnSEd2GT92fkgZl0pz0Q0AzcIQ==" + "integrity": "sha512-fAtCfv4jJg+ExtXhvCkCqUKZ+4ok/JQk01qDKhL5BDDoS3AxKXhV5/MAVUZyQnSEd2GT92fkgZl0pz0Q0AzcIQ==", + "license": "MIT" }, "node_modules/@types/stack-utils": { "version": "2.0.3", diff --git a/package.json b/package.json index c73ca59..072e62c 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "build": "tsc && chmod +x dist/index.js", "start": "node dist/index.js", + "test": "NODE_OPTIONS=--experimental-vm-modules jest --config jest.config.mjs", "test:list": "node --loader ts-node/esm src/index.ts list", "test:install": "node --loader ts-node/esm src/index.ts install", "test:installed": "node --loader ts-node/esm src/index.ts installed", @@ -41,7 +42,7 @@ "@types/inquirer": "^8.2.4", "@types/inquirer-autocomplete-prompt": "^3.0.3", "@types/jest": "^29.5.14", - "@types/node": "^14.0.0", + "@types/node": "^14.18.63", "jest": "^29.7.0", "ts-jest": "^29.2.5", "ts-node": "^10.9.1" diff --git a/src/utils/__tests__/config-manager.test.ts b/src/utils/__tests__/config-manager.test.ts new file mode 100644 index 0000000..80eb19b --- /dev/null +++ b/src/utils/__tests__/config-manager.test.ts @@ -0,0 +1,42 @@ +import { jest, describe, it, expect, beforeEach } from '@jest/globals'; +import { ConfigManager } from '../config-manager'; +import { Package } from '../../types/package'; +import fs from 'fs'; +import path from 'path'; + +jest.mock('fs'); +jest.mock('path'); + +describe('ConfigManager', () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + describe('installPackage', () => { + it('should create config with "env" key for environment variables', async () => { + const mockPackage: Package = { + name: 'test-package', + description: 'Test package for config manager', + runtime: 'node', + vendor: 'test-vendor', + sourceUrl: 'https://github.com/test/test-package', + homepage: 'https://test-package.com', + license: 'MIT' + }; + + const mockEnvVars = { + TEST_KEY: 'test-value' + }; + + const writeFileSpy = jest.spyOn(fs, 'writeFileSync'); + + await ConfigManager.installPackage(mockPackage, mockEnvVars); + + expect(writeFileSpy).toHaveBeenCalled(); + const writtenConfig = JSON.parse(writeFileSpy.mock.calls[0][1] as string); + expect(writtenConfig.mcpServers['test-package'].env).toBeDefined(); + expect(writtenConfig.mcpServers['test-package'].envVars).toBeUndefined(); + expect(writtenConfig.mcpServers['test-package'].env).toEqual(mockEnvVars); + }); + }); +}); diff --git a/src/utils/config-manager.ts b/src/utils/config-manager.ts index 02c1f35..f9d3f72 100644 --- a/src/utils/config-manager.ts +++ b/src/utils/config-manager.ts @@ -7,7 +7,7 @@ export interface MCPServer { runtime: 'node' | 'python'; command?: string; args?: string[]; - envVars?: Record; + env?: Record; // Changed from envVars to env } export interface MCPConfig { @@ -106,10 +106,10 @@ export class ConfigManager { static async installPackage(pkg: Package, envVars?: Record): Promise { const config = this.readConfig(); const serverName = pkg.name.replace(/\//g, '-'); - + const serverConfig: MCPServer = { runtime: pkg.runtime, - envVars + env: envVars // Changed from envVars to env }; // Add command and args based on runtime @@ -128,12 +128,12 @@ export class ConfigManager { static async uninstallPackage(packageName: string): Promise { const config = this.readConfig(); const serverName = packageName.replace(/\//g, '-'); - + if (!config.mcpServers || !config.mcpServers[serverName]) { console.log(`Package ${packageName} is not installed.`); return; } - + delete config.mcpServers[serverName]; this.writeConfig(config); } From 480ddcea23aaddf20b3bf2c8b2d152a7adb28352 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 12 Dec 2024 14:18:33 +0000 Subject: [PATCH 2/3] ci: add Jest test workflow for PRs Co-Authored-By: Michael Latman --- .github/workflows/jest-tests.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/jest-tests.yml diff --git a/.github/workflows/jest-tests.yml b/.github/workflows/jest-tests.yml new file mode 100644 index 0000000..a426d43 --- /dev/null +++ b/.github/workflows/jest-tests.yml @@ -0,0 +1,23 @@ +name: Jest Tests + +on: + pull_request: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '18' + + - name: Install dependencies + run: npm ci + + - name: Run Jest tests + run: npm test From 53edfea8e92b4dec94e493cd3dadfe1e588b1856 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 12 Dec 2024 14:25:40 +0000 Subject: [PATCH 3/3] chore: remove inline comments from config-manager.ts Co-Authored-By: Michael Latman --- src/utils/config-manager.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/config-manager.ts b/src/utils/config-manager.ts index f9d3f72..6d19755 100644 --- a/src/utils/config-manager.ts +++ b/src/utils/config-manager.ts @@ -7,7 +7,7 @@ export interface MCPServer { runtime: 'node' | 'python'; command?: string; args?: string[]; - env?: Record; // Changed from envVars to env + env?: Record; } export interface MCPConfig { @@ -109,7 +109,7 @@ export class ConfigManager { const serverConfig: MCPServer = { runtime: pkg.runtime, - env: envVars // Changed from envVars to env + env: envVars }; // Add command and args based on runtime