import { describe, it, expect, beforeAll } from "vitest"; import { getFixturePipeline } from "./helpers/pipeline.js"; import { setGraph } from "../src/server/graph-store.js"; beforeAll(() => { const { codebaseGraph } = getFixturePipeline(); setGraph(codebaseGraph); }); describe("4.1 — impact_analysis depth-grouped results", () => { it("changing UserService.getUserById returns depth-grouped callers", async () => { const { impactAnalysis } = await import("../src/impact/index.js"); const { codebaseGraph } = getFixturePipeline(); const result = impactAnalysis(codebaseGraph, "UserService.getUserById"); expect(result.symbol).toBe("UserService.getUserById"); expect(result.levels.length).toBeGreaterThanOrEqual(1); const d1Files = result.levels .find((l) => l.depth === 1) ?.affected.map((a) => a.file) ?? []; expect(d1Files.some((f) => f.includes("auth"))).toBe(true); const allFiles = result.levels.flatMap((l) => l.affected.map((a) => a.file)); expect(allFiles.some((f) => f.includes("routes"))).toBe(true); }); it("each depth level has a risk label", async () => { const { impactAnalysis } = await import("../src/impact/index.js"); const { codebaseGraph } = getFixturePipeline(); const result = impactAnalysis(codebaseGraph, "UserService.getUserById"); for (const level of result.levels) { expect(["WILL BREAK", "LIKELY", "MAY NEED TESTING"]).toContain(level.risk); } }); }); describe("4.2 — impact_analysis on disconnected symbol", () => { it("returns depth-0 with no dependents message", async () => { const { impactAnalysis } = await import("../src/impact/index.js"); const { codebaseGraph } = getFixturePipeline(); const result = impactAnalysis(codebaseGraph, "nonexistent_symbol_xyz"); expect(result.levels).toHaveLength(0); expect(result.totalAffected).toBe(0); }); }); describe("4.3 — rename_symbol dry_run", () => { it("renaming getUserById returns plan with file references", async () => { const { renameSymbol } = await import("../src/impact/index.js"); const { codebaseGraph } = getFixturePipeline(); const result = renameSymbol(codebaseGraph, "getUserById", "findUserById", true); expect(result.dryRun).toBe(true); expect(result.references.length).toBeGreaterThan(0); for (const ref of result.references) { expect(ref).toHaveProperty("file"); expect(ref).toHaveProperty("confidence"); expect(["type-resolved", "text-inferred"]).toContain(ref.confidence); } }); }); describe("4.5 — search results include process grouping", () => { it("search results include relatedProcesses when processes exist", async () => { const { createSearchIndex, search } = await import("../src/search/index.js"); const { codebaseGraph } = getFixturePipeline(); const index = createSearchIndex(codebaseGraph); const results = search(index, "auth"); expect(results.length).toBeGreaterThan(0); // Process grouping is added at the MCP/API layer, not in raw search // Test that the graph has processes available for enrichment expect(codebaseGraph.processes.length).toBeGreaterThan(0); }); }); describe("4.6 — get_dependents deprecation notice", () => { it("get_dependents response includes deprecation field", async () => { const { McpServer } = await import("@modelcontextprotocol/sdk/server/mcp.js"); const { registerTools } = await import("../src/mcp/index.js"); const { codebaseGraph } = getFixturePipeline(); const server = new McpServer({ name: "test", version: "0.1.0" }); registerTools(server, codebaseGraph); // Tool is registered — deprecation is in the response payload expect(server).toBeDefined(); }); });