Skip to main content
Glama
cognitive.test.ts6.68 kB
import { describe, it, expect } from "vitest"; import { planTaskHandler, reflectOnCodeHandler, analyzeArchitectureHandler, debugProblemHandler, brainstormSolutionsHandler, compareApproachesHandler, estimateComplexityHandler, generateTestsHandler, explainCodeHandler, } from "./cognitive.js"; describe("Cognitive Tools", () => { describe("planTaskHandler", () => { it("should generate a smart task plan", () => { const result = planTaskHandler({ task: "Refactor Auth", context: "Using JWT with Express", scope: "medium", }); const text = result.content[0].text; expect(text).toContain("# Smart Task Plan: Refactor Auth"); expect(text).toContain("Refactoring Mode Detected"); expect(text).toContain("Security Context Detected"); }); it("should suggest frontend steps for UI tasks", () => { const result = planTaskHandler({ task: "Create Login Page", context: "React, Tailwind", scope: "small", }); const text = result.content[0].text; expect(text).toContain("Build UI components"); expect(text).toContain("Integrate with API/State"); expect(text).toContain("Verify responsiveness/accessibility"); }); it("should suggest backend steps for API tasks", () => { const result = planTaskHandler({ task: "Update User API", context: "Express, Node, MongoDB", scope: "medium", }); const text = result.content[0].text; expect(text).toContain("Implement core logic/API"); expect(text).toContain("database migrations"); // triggered by MongoDB/db context }); }); describe("reflectOnCodeHandler", () => { it("should analyze code quality", () => { const result = reflectOnCodeHandler({ code: "const a = 1;", language: "typescript", focus: ["quality"], }); expect(result.content[0].text).toContain("# Code Reflection (typescript)"); expect(result.content[0].text).toContain("Quality Analysis"); }); }); describe("analyzeArchitectureHandler", () => { it("should analyze system description", () => { const result = analyzeArchitectureHandler({ description: "Microservices architecture", components: ["Auth Service", "User Service"], }); expect(result.content[0].text).toContain("# Architecture Analysis"); expect(result.content[0].text).toContain("Auth Service"); }); }); describe("debugProblemHandler", () => { it("should provide debug strategy", () => { const result = debugProblemHandler({ problem: "Memory leak in worker", symptoms: ["High RAM usage"], }); expect(result.content[0].text).toContain( "# Debug Analysis: Memory leak in worker", ); expect(result.content[0].text).toContain("High RAM usage"); expect(result.content[0].text).toContain("Phase 1: Reproduce"); }); }); describe("brainstormSolutionsHandler", () => { it("should generate solution approaches", () => { const result = brainstormSolutionsHandler({ problem: "Scale websocket server", }); expect(result.content[0].text).toContain( "# Brainstorm: Scale websocket server", ); expect(result.content[0].text).toContain("Approach 1: Simple/Direct"); }); }); describe("compareApproachesHandler", () => { it("should generate comparison matrix", () => { const result = compareApproachesHandler({ approaches: ["REST", "GraphQL", "gRPC"], criteria: ["Performance", "Flexibility"], }); expect(result.content[0].text).toContain("# Approach Comparison"); expect(result.content[0].text).toContain( "| Criterion | REST | GraphQL | gRPC |", ); expect(result.content[0].text).toContain("Flexibility"); }); }); describe("brainstorm_solutions", () => { it("should return a markdown set of solutions", () => { const result = brainstormSolutionsHandler({ problem: "How to scale a database?", }); const text = result.content[0].text; expect(text).toContain("Brainstorm: How to scale a database?"); expect(text).toContain("Solution Approaches"); }); it("should suggest perspectives based on keywords", () => { const result = brainstormSolutionsHandler({ problem: "How to improve security for user auth?", }); const text = result.content[0].text; expect(text).toContain("Zero-Trust (Security Focus)"); expect(text).toContain("User-Centric (UX Focus)"); }); }); describe("estimate_complexity", () => { it("should return a complexity estimate", () => { const result = estimateComplexityHandler({ task: "Build a simple form", }); const text = result.content[0].text; expect(text).toContain("Complexity Estimate: Build a simple form"); expect(text).toContain("Effort Breakdown"); }); it("should detect high complexity based on keywords", () => { const result = estimateComplexityHandler({ task: "Refactor legacy crypto payment database", }); const text = result.content[0].text; expect(text).toContain("Detected Keywords"); expect(text).toContain("High"); // Risk level }); }); describe("estimateComplexityHandler", () => { it("should estimate complexity", () => { const result = estimateComplexityHandler({ task: "Add dark mode", }); expect(result.content[0].text).toContain( "# Complexity Estimate: Add dark mode", ); expect(result.content[0].text).toContain("Effort Breakdown"); }); }); describe("generateTestsHandler", () => { it("should suggest tests", () => { const result = generateTestsHandler({ feature: "Login Form", type: "unit", }); expect(result.content[0].text).toContain("# Test Cases: Login Form"); expect(result.content[0].text).toContain("Unit Tests"); // The header "Integration Tests" is always present, but content says "Not requested" expect(result.content[0].text).toContain("Integration Tests"); expect(result.content[0].text).toContain("Not requested"); }); }); describe("explainCodeHandler", () => { it("should explain code", () => { const result = explainCodeHandler({ code: "function add(a,b) { return a+b; }", language: "javascript", }); expect(result.content[0].text).toContain( "# Code Explanation (javascript)", ); expect(result.content[0].text).toContain("Code Overview"); }); }); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/millsydotdev/Code-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server