UNPKG

@agentdesk/workflows-mcp

Version:

MCP workflow orchestration tool with presets for thinking, coding and more

189 lines 7.75 kB
import { expect } from "chai"; import { loadConfigSync, validateToolConfig, } from "../config.js"; import path from "path"; import fs from "fs"; import os from "os"; import yaml from "js-yaml"; describe("Configuration", () => { let tempJsConfigPath; let tempYamlConfigPath; let tempJsonConfigPath; let tempDir; before(() => { // Create a temporary directory for test config files tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "devtools-config-")); // Create a JS config file for testing tempJsConfigPath = path.join(tempDir, "test-config.js"); const jsConfigContent = ` { debugger_mode: { additionalContext: "Test additional context", availableTools: [ { name: "test-tool", description: "A test tool" } ], toolMode: "sequential" }, architecture_mode: { customPrompt: "Custom architecture prompt" } } `; fs.writeFileSync(tempJsConfigPath, jsConfigContent, "utf8"); // Create a YAML config file for testing tempYamlConfigPath = path.join(tempDir, "test-config.yaml"); const yamlConfig = { debugger_mode: { additionalContext: "Test YAML additional context", availableTools: [ { name: "yaml-test-tool", description: "A YAML test tool", }, ], toolMode: "sequential", }, architecture_mode: { customPrompt: "Custom YAML architecture prompt", }, }; fs.writeFileSync(tempYamlConfigPath, yaml.dump(yamlConfig), "utf8"); // Create a JSON config file for testing tempJsonConfigPath = path.join(tempDir, "test-config.json"); const jsonConfig = { debugger_mode: { additionalContext: "Test JSON additional context", availableTools: [ { name: "json-test-tool", description: "A JSON test tool", }, ], toolMode: "sequential", }, architecture_mode: { customPrompt: "Custom JSON architecture prompt", }, }; fs.writeFileSync(tempJsonConfigPath, JSON.stringify(jsonConfig, null, 2), "utf8"); }); after(() => { // Clean up the temporary config files if (tempDir && fs.existsSync(tempDir)) { if (tempJsConfigPath && fs.existsSync(tempJsConfigPath)) { fs.unlinkSync(tempJsConfigPath); } if (tempYamlConfigPath && fs.existsSync(tempYamlConfigPath)) { fs.unlinkSync(tempYamlConfigPath); } if (tempJsonConfigPath && fs.existsSync(tempJsonConfigPath)) { fs.unlinkSync(tempJsonConfigPath); } fs.rmdirSync(tempDir); } }); describe("loadConfig", () => { it("should load a valid YAML configuration file", () => { const config = loadConfigSync(tempYamlConfigPath); expect(config).to.be.an("object"); expect(config.debugger_mode).to.exist; expect(config.debugger_mode?.additionalContext).to.equal("Test YAML additional context"); expect(config.architecture_mode?.customPrompt).to.equal("Custom YAML architecture prompt"); }); it("should load a valid JSON configuration file", () => { const config = loadConfigSync(tempJsonConfigPath); expect(config).to.be.an("object"); expect(config.debugger_mode).to.exist; expect(config.debugger_mode?.additionalContext).to.equal("Test JSON additional context"); expect(config.architecture_mode?.customPrompt).to.equal("Custom JSON architecture prompt"); }); it("should load a valid JS configuration file (legacy support)", () => { const config = loadConfigSync(tempJsConfigPath); expect(config).to.be.an("object"); expect(config.debugger_mode).to.exist; expect(config.debugger_mode?.additionalContext).to.equal("Test additional context"); expect(config.architecture_mode?.customPrompt).to.equal("Custom architecture prompt"); }); it("should return default config when path is not provided", () => { const config = loadConfigSync(); expect(config).to.be.an("object"); expect(Object.keys(config).length).to.equal(0); }); it("should return default config when file does not exist", () => { const config = loadConfigSync("/non/existent/path.js"); expect(config).to.be.an("object"); expect(Object.keys(config).length).to.equal(0); }); }); describe("validateToolConfig", () => { it("should return null for valid configuration", () => { const config = { debugger_mode: { additionalContext: "Valid context", availableTools: [ { name: "tool1", description: "Tool 1", }, ], toolMode: "situational", }, }; const result = validateToolConfig(config, "debugger_mode"); expect(result).to.be.null; }); it("should return error for invalid toolMode", () => { const config = { debugger_mode: { // @ts-ignore - testing invalid value toolMode: "invalid-mode", }, }; const result = validateToolConfig(config, "debugger_mode"); expect(result).to.include("Invalid toolMode"); }); it("should return error for invalid availableTools", () => { const config = { debugger_mode: { // @ts-ignore - testing invalid value availableTools: "not-an-array", }, }; const result = validateToolConfig(config, "debugger_mode"); expect(result).to.include("must be an array"); }); it("should return error for tool without name", () => { // Create config with type assertion to bypass TypeScript's type checking const config = { debugger_mode: { availableTools: [ { // name is intentionally missing description: "Missing name", }, ], }, }; const result = validateToolConfig(config, "debugger_mode"); expect(result).to.include("name property"); }); it("should return error for tool without description", () => { // Create config with type assertion to bypass TypeScript's type checking const config = { debugger_mode: { availableTools: [ { name: "tool-without-description", // description is intentionally missing }, ], }, }; const result = validateToolConfig(config, "debugger_mode"); expect(result).to.include("description property"); }); }); }); //# sourceMappingURL=config.test.js.map