mcp-server-debug-thinking
Version:
Graph-based MCP server for systematic debugging using Problem-Solution Trees and Hypothesis-Experiment-Learning cycles
61 lines • 2.7 kB
JavaScript
import { describe, it, expect, beforeEach, afterEach } from "vitest";
import { GraphService } from "../../services/GraphService.js";
import { ActionType } from "../../types/graphActions.js";
describe("GraphService - Debug similarity threshold", () => {
let graphService;
beforeEach(async () => {
process.env.DEBUG_DATA_DIR = `.test-debug-${Date.now()}`;
graphService = new GraphService();
await graphService.initialize();
});
afterEach(async () => {
if (process.env.DEBUG_DATA_DIR) {
const fs = await import("fs/promises");
try {
await fs.rm(process.env.DEBUG_DATA_DIR, { recursive: true, force: true });
}
catch (_error) {
// Directory might not exist
}
delete process.env.DEBUG_DATA_DIR;
}
});
it("should calculate similarity correctly", () => {
// @ts-ignore - accessing private method for testing
const similarity = graphService.calculateSimilarity("Any pattern", "Test problem");
console.log("Similarity between 'Any pattern' and 'Test problem':", similarity);
expect(similarity).toBeGreaterThanOrEqual(0);
expect(similarity).toBeLessThanOrEqual(1);
});
it("should find problems with similarity threshold 0", async () => {
// Create a test problem
const createResult = await graphService.create({
action: ActionType.CREATE,
nodeType: "problem",
content: "Test problem",
});
const createResponse = JSON.parse(createResult.content[0].text);
expect(createResponse.success).toBe(true);
console.log("Created problem:", createResponse.nodeId);
// Check if the problem exists in the graph
const graph = graphService.getGraph();
console.log("Total nodes in graph:", graph.nodes.size);
console.log("Problem nodes:", [...graph.nodes.values()]
.filter(n => n.type === "problem")
.map(n => ({ id: n.id, content: n.content })));
// Search with similarity threshold 0
const searchResult = await graphService.query({
action: ActionType.QUERY,
type: "similar-problems",
parameters: {
pattern: "Any pattern",
minSimilarity: 0,
},
});
const searchResponse = JSON.parse(searchResult.content[0].text);
console.log("Search response:", searchResponse);
expect(searchResponse.success).toBe(true);
expect(searchResponse.results.problems.length).toBeGreaterThan(0);
});
});
//# sourceMappingURL=GraphServiceDebug.test.js.map