import { describe, it, expect } from "vitest";
import { reflectOnCodeHandler } from "./cognitive.js";
import { securityScanHandler } from "./quality.js";
import { suggestToolChainHandler } from "./coordination.js";
describe("Tool Accuracy Improvements", () => {
describe("security_scan", () => {
it("should detect hardcoded secrets", () => {
const badCode = "const apiKey = '12345678-abcd-1234-abcd-1234567890ab';";
const result = securityScanHandler({
code: badCode,
language: "typescript",
focus: "secrets",
});
expect(result.content[0].text).toContain("Hardcoded secret detected");
});
it("should detect dangerous execution", () => {
const badCode = "eval('alert(1)');";
const result = securityScanHandler({
code: badCode,
language: "javascript",
focus: "injection",
});
expect(result.content[0].text).toContain("RCE Risk");
});
it("should detect react xss", () => {
const badCode = "<div dangerouslySetInnerHTML={{__html: 'test'}} />";
const result = securityScanHandler({
code: badCode,
language: "typescript",
focus: "injection",
});
expect(result.content[0].text).toContain("XSS Risk");
});
});
describe("reflect_on_code", () => {
it("should detect long files", () => {
const longCode = Array(305).fill("const a = 1;").join("\n");
const result = reflectOnCodeHandler({
code: longCode,
language: "typescript",
});
expect(result.content[0].text).toContain("File Size");
});
it("should detect missing docstrings", () => {
const code = "export function test() { return 1; }";
const result = reflectOnCodeHandler({
code,
language: "typescript",
focus: ["quality"],
});
expect(result.content[0].text).toContain("No JSDoc/comments found");
});
it("should detect TODOs", () => {
const code =
"// TODO: fix this\n// TODO: and this\n// TODO: and that\n// TODO: and more";
const result = reflectOnCodeHandler({
code,
language: "typescript",
focus: ["maintainability"],
});
expect(result.content[0].text).toContain("TODOs found");
});
});
describe("suggest_tool_chain", () => {
it("should suggest refactoring workflow", () => {
const result = suggestToolChainHandler({ goal: "Refactor legacy code" });
expect(result.content[0].text).toContain("Refactoring Workflow");
expect(result.content[0].text).toContain("derive_patterns");
});
it("should suggest debugging workflow", () => {
const result = suggestToolChainHandler({ goal: "Fix the bug in login" });
expect(result.content[0].text).toContain("Debugging Workflow");
expect(result.content[0].text).toContain("act_as_debugger");
});
it("should suggest devops workflow", () => {
const result = suggestToolChainHandler({ goal: "Deploy to AWS" });
expect(result.content[0].text).toContain("DevOps Workflow");
expect(result.content[0].text).toContain("generate_terraform_config");
});
});
});