Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
🧫 chore: Keep Jest Specs Out of Tool Discovery (#15766)
Danny Avila0d85af0a774d
diff --git a/api/app/clients/tools/structured/AzureAISearch.spec.js b/api/app/clients/tools/structured/specs/AzureAISearch.spec.jssimilarity index 95%rename from api/app/clients/tools/structured/AzureAISearch.spec.jsrename to api/app/clients/tools/structured/specs/AzureAISearch.spec.jsindex abedd24a2a..f586e1e1f8 100644--- a/api/app/clients/tools/structured/AzureAISearch.spec.js+++ b/api/app/clients/tools/structured/specs/AzureAISearch.spec.js@@ -23,7 +23,7 @@ jest.mock({ virtual: true },);-const AzureAISearch = require('./AzureAISearch');+const AzureAISearch = require('../AzureAISearch');describe('AzureAISearch', () => {const requiredFields = {diff --git a/api/app/clients/tools/structured/StableDiffusion.spec.js b/api/app/clients/tools/structured/specs/StableDiffusion.spec.jssimilarity index 96%rename from api/app/clients/tools/structured/StableDiffusion.spec.jsrename to api/app/clients/tools/structured/specs/StableDiffusion.spec.jsindex 7f58c4e2a0..8b4b35eba9 100644--- a/api/app/clients/tools/structured/StableDiffusion.spec.js+++ b/api/app/clients/tools/structured/specs/StableDiffusion.spec.js@@ -29,7 +29,7 @@ jest.mock('@librechat/api', () => ({}));jest.mock('~/config/paths', () => ({}), { virtual: true });-const StableDiffusionAPI = require('./StableDiffusion');+const StableDiffusionAPI = require('../StableDiffusion');describe('StableDiffusionAPI', () => {beforeEach(() => {diff --git a/api/server/services/start/__tests__/tools.spec.js b/api/server/services/start/__tests__/tools.spec.jsnew file mode 100644index 0000000000..6bd7f60e83--- /dev/null+++ b/api/server/services/start/__tests__/tools.spec.js@@ -0,0 +1,50 @@+const fs = require('fs');+const os = require('os');+const path = require('path');+const { loadAndFormatTools } = require('../tools');++describe('loadAndFormatTools', () => {+ let directory;++ beforeEach(() => {+ directory = fs.mkdtempSync(path.join(os.tmpdir(), 'librechat-tools-'));+ const toolPath = require.resolve('@librechat/agents/langchain/tools');+ fs.writeFileSync(+ path.join(directory, 'Example.js'),+ `const { Tool } = require(${JSON.stringify(toolPath)});+ module.exports = class extends Tool {+ constructor() {+ super();+ this.name = 'example';+ this.description = 'Example tool';+ }+ async _call() { return 'example'; }+ };`,+ );+ for (const file of ['Example.spec.js', 'Example.test.js']) {+ fs.writeFileSync(+ path.join(directory, file),+ `require('fs').writeFileSync(${JSON.stringify(path.join(directory, `${file}.loaded`))}, 'loaded');+ throw new Error('Test module must not execute during tool discovery');`,+ );+ }+ });++ afterEach(() => {+ fs.rmSync(directory, { recursive: true, force: true });+ });++ it.each([+ { adminIncluded: [] },+ { adminIncluded: ['Example.js', 'Example.spec.js', 'Example.test.js'] },+ ])(+ 'skips test modules before execution with includedTools=$adminIncluded',+ ({ adminIncluded }) => {+ const tools = loadAndFormatTools({ directory, adminIncluded });++ expect(tools.example.function.name).toBe('example');+ expect(fs.existsSync(path.join(directory, 'Example.spec.js.loaded'))).toBe(false);+ expect(fs.existsSync(path.join(directory, 'Example.test.js.loaded'))).toBe(false);+ },+ );+});diff --git a/api/server/services/start/tools.js b/api/server/services/start/tools.jsindex c6073b3a73..629624c500 100644--- a/api/server/services/start/tools.js+++ b/api/server/services/start/tools.js@@ -7,6 +7,7 @@ const { Tool } = require('@librechat/agents/langchain/tools');const { Tools, ImageVisionTool } = require('librechat-data-provider');const {getToolkitKey,+ isToolModuleFile,oaiToolkit,geminiToolkit,createAskUserQuestionTool,@@ -16,7 +17,7 @@ const { toolkits } = require('~/app/clients/tools/manifest');/*** Loads and formats tools from the specified tool directory.*- * The directory is scanned for JavaScript files, excluding any files in the filter set.+ * The directory is scanned for JavaScript files, excluding test files and any files in the filter set.* For each file, it attempts to load the file as a module and instantiate a class, if it's a subclass of `StructuredTool`.* Each tool instance is then formatted to be compatible with the OpenAI Assistant.* Additionally, instances of LangChain Tools are included in the result.@@ -42,7 +43,7 @@ function loadAndFormatTools({ directory, adminFilter = [], adminIncluded = [] })for (const file of files) {const filePath = path.join(directory, file);- if (!file.endsWith('.js') || (filter.has(file) && included.size === 0)) {+ if (!isToolModuleFile(file) || (filter.has(file) && included.size === 0)) {continue;}diff --git a/packages/api/src/tools/discovery.ts b/packages/api/src/tools/discovery.tsnew file mode 100644index 0000000000..2f90b17f39--- /dev/null+++ b/packages/api/src/tools/discovery.ts@@ -0,0 +1,3 @@+export function isToolModuleFile(filename: string): boolean {+ return filename.endsWith('.js') && !/\.(spec|test)\.js$/.test(filename);+}diff --git a/packages/api/src/tools/index.ts b/packages/api/src/tools/index.tsindex d48daea26b..d901755b7c 100644--- a/packages/api/src/tools/index.ts+++ b/packages/api/src/tools/index.ts@@ -1,4 +1,5 @@export * from './format';+export * from './discovery';export * from './protection';export * from './registry';export * from './toolkits';